
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Linux Shell · AGou's StudyNote</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="AGou">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism-tomorrow.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-lightbox/css/lightbox.min.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="shell_awk.html" />
    
    
    <link rel="prev" href="iptables.html" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"repo":"AGou-ops/myStudyNote","types":["star","watch","fork"],"size":"small"};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="http://agou-ops.github.io" target="_blank" class="custom-link">◆点击进入我的个人博客</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                        <b>1.1.</b>
                    
                    关于我
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../Program_lang/">
            
                <a href="../Program_lang/">
            
                    
                        <b>1.2.</b>
                    
                    编程语言
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Program_lang/Python.html">
            
                <a href="../Program_lang/Python.html">
            
                    
                        <b>1.2.1.</b>
                    
                    Python
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../Program_lang/Java.html">
            
                <a href="../Program_lang/Java.html">
            
                    
                        <b>1.2.2.</b>
                    
                    Java
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../Program_lang/Splash_Lua.html">
            
                <a href="../Program_lang/Splash_Lua.html">
            
                    
                        <b>1.2.3.</b>
                    
                    Splash_Lua
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../Database/">
            
                <a href="../Database/">
            
                    
                        <b>1.3.</b>
                    
                    数据库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../Database/Mysql、MariaDB/README.md">
            
                <span>
            
                    
                        <b>1.3.1.</b>
                    
                    Mysql/MariaDB
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1.1" data-path="../Database/Mysql、MariaDB/MySQL、MariaDB基础.html">
            
                <a href="../Database/Mysql、MariaDB/MySQL、MariaDB基础.html">
            
                    
                        <b>1.3.1.1.</b>
                    
                    MySQL/MariaDB基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.1.2" data-path="../Database/Mysql、MariaDB/php-mysql.html">
            
                <a href="../Database/Mysql、MariaDB/php-mysql.html">
            
                    
                        <b>1.3.1.2.</b>
                    
                    php-mysql
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../Database/MongoDB.html">
            
                <a href="../Database/MongoDB.html">
            
                    
                        <b>1.3.2.</b>
                    
                    MongoDB
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../Database/Redis.html">
            
                <a href="../Database/Redis.html">
            
                    
                        <b>1.3.3.</b>
                    
                    Redis
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="./">
            
                <a href="./">
            
                    
                        <b>1.4.</b>
                    
                    Linux
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="Linux基础.html">
            
                <a href="Linux基础.html">
            
                    
                        <b>1.4.1.</b>
                    
                    Linux基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="Linux启动流程、内核、grub、模块、内核的编译、anaconda自动化.html">
            
                <a href="Linux启动流程、内核、grub、模块、内核的编译、anaconda自动化.html">
            
                    
                        <b>1.4.2.</b>
                    
                    Linux启动流程、内核、grub、模块等
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="Linux服务器.html">
            
                <a href="Linux服务器.html">
            
                    
                        <b>1.4.3.</b>
                    
                    Linux服务器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="Linux状态信息.html">
            
                <a href="Linux状态信息.html">
            
                    
                        <b>1.4.4.</b>
                    
                    Linux状态信息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="Linux网络客户端工具.html">
            
                <a href="Linux网络客户端工具.html">
            
                    
                        <b>1.4.5.</b>
                    
                    Linux网络客户端工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="Linux网络配置.html">
            
                <a href="Linux网络配置.html">
            
                    
                        <b>1.4.6.</b>
                    
                    Linux网络配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="Linux配置文件.md">
            
                <span>
            
                    
                        <b>1.4.7.</b>
                    
                    Linux配置文件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="Linux时间服务器.html">
            
                <a href="Linux时间服务器.html">
            
                    
                        <b>1.4.8.</b>
                    
                    Linux时间服务器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="Linux日志管理系统.html">
            
                <a href="Linux日志管理系统.html">
            
                    
                        <b>1.4.9.</b>
                    
                    Linux日志管理系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="sudo详解.html">
            
                <a href="sudo详解.html">
            
                    
                        <b>1.4.10.</b>
                    
                    sudo详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.11" data-path="SElinux.html">
            
                <a href="SElinux.html">
            
                    
                        <b>1.4.11.</b>
                    
                    SELinux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.12" data-path="iptables.html">
            
                <a href="iptables.html">
            
                    
                        <b>1.4.12.</b>
                    
                    iptables
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4.13" data-path="Linux_shell.html">
            
                <a href="Linux_shell.html">
            
                    
                        <b>1.4.13.</b>
                    
                    Linux Shell
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.14" data-path="shell_awk.html">
            
                <a href="shell_awk.html">
            
                    
                        <b>1.4.14.</b>
                    
                    shell_awk
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.15" data-path="OpenSSL、PKI搭建、算法.html">
            
                <a href="OpenSSL、PKI搭建、算法.html">
            
                    
                        <b>1.4.15.</b>
                    
                    OpenSSL、PKI搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.16" data-path="DNS服务器.html">
            
                <a href="DNS服务器.html">
            
                    
                        <b>1.4.16.</b>
                    
                    DNS服务器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.17" data-path="Frp内网穿透.html">
            
                <a href="Frp内网穿透.html">
            
                    
                        <b>1.4.17.</b>
                    
                    Frp内网穿透
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.18" data-path="Linux其他.md">
            
                <span>
            
                    
                        <b>1.4.18.</b>
                    
                    Linux其他
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../Linux_FileSystem/">
            
                <a href="../Linux_FileSystem/">
            
                    
                        <b>1.5.</b>
                    
                    Linux文件系统
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Linux_FileSystem/FTP.html">
            
                <a href="../Linux_FileSystem/FTP.html">
            
                    
                        <b>1.5.1.</b>
                    
                    FTP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Linux_FileSystem/SAMBA.html">
            
                <a href="../Linux_FileSystem/SAMBA.html">
            
                    
                        <b>1.5.2.</b>
                    
                    SAMBA
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../Linux_Tools/">
            
                <a href="../Linux_Tools/">
            
                    
                        <b>1.6.</b>
                    
                    Linux工具
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../Linux_Tools/fzf工具.html">
            
                <a href="../Linux_Tools/fzf工具.html">
            
                    
                        <b>1.6.1.</b>
                    
                    fzf工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../Linux_Tools/工具集合.html">
            
                <a href="../Linux_Tools/工具集合.html">
            
                    
                        <b>1.6.2.</b>
                    
                    Linux工具集合
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../WEB_Server/">
            
                <a href="../WEB_Server/">
            
                    
                        <b>1.7.</b>
                    
                    网站服务器
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../WEB_Server/HTML基础.html">
            
                <a href="../WEB_Server/HTML基础.html">
            
                    
                        <b>1.7.1.</b>
                    
                    HTML基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../WEB_Server/WEB基础.html">
            
                <a href="../WEB_Server/WEB基础.html">
            
                    
                        <b>1.7.2.</b>
                    
                    WEB基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../WEB_Server/httpd.html">
            
                <a href="../WEB_Server/httpd.html">
            
                    
                        <b>1.7.3.</b>
                    
                    httpd/Apache
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../WEB_Server/httpd.conf文件详解.html">
            
                <a href="../WEB_Server/httpd.conf文件详解.html">
            
                    
                        <b>1.7.4.</b>
                    
                    httpd.conf文件详解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../WEB_Server/Nginx.html">
            
                <a href="../WEB_Server/Nginx.html">
            
                    
                        <b>1.7.5.</b>
                    
                    Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../WEB_Server/HTTP状态码-详情.html">
            
                <a href="../WEB_Server/HTTP状态码-详情.html">
            
                    
                        <b>1.7.6.</b>
                    
                    HTTP状态码-详情
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../Common_Framework/">
            
                <a href="../Common_Framework/">
            
                    
                        <b>1.8.</b>
                    
                    常用框架
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../Common_Framework/LNMP.html">
            
                <a href="../Common_Framework/LNMP.html">
            
                    
                        <b>1.8.1.</b>
                    
                    LNMP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../Common_Framework/LAMP.html">
            
                <a href="../Common_Framework/LAMP.html">
            
                    
                        <b>1.8.2.</b>
                    
                    LAMP
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../Docker&K8s/">
            
                <a href="../Docker&K8s/">
            
                    
                        <b>1.9.</b>
                    
                    容器及容器编排
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../Docker&K8s/Docker/Docker.html">
            
                <a href="../Docker&K8s/Docker/Docker.html">
            
                    
                        <b>1.9.1.</b>
                    
                    Docker
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1.1" data-path="../Docker&K8s/Docker/Docker.html">
            
                <a href="../Docker&K8s/Docker/Docker.html">
            
                    
                        <b>1.9.1.1.</b>
                    
                    Docker
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../Docker&K8s/K8s/">
            
                <a href="../Docker&K8s/K8s/">
            
                    
                        <b>1.9.2.</b>
                    
                    K8s
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.2.1" data-path="../Docker&K8s/K8s/K8s基础知识.html">
            
                <a href="../Docker&K8s/K8s/K8s基础知识.html">
            
                    
                        <b>1.9.2.1.</b>
                    
                    K8s基础知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2.2" data-path="../Docker&K8s/K8s/K8s安装与部署.html">
            
                <a href="../Docker&K8s/K8s/K8s安装与部署.html">
            
                    
                        <b>1.9.2.2.</b>
                    
                    K8s安装与部署
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../Git/">
            
                <a href="../Git/">
            
                    
                        <b>1.10.</b>
                    
                    Git
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../Git/Git基础.html">
            
                <a href="../Git/Git基础.html">
            
                    
                        <b>1.10.1.</b>
                    
                    Git基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../Git/GitLab服务器.html">
            
                <a href="../Git/GitLab服务器.html">
            
                    
                        <b>1.10.2.</b>
                    
                    GitLab服务器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../Windows/">
            
                <a href="../Windows/">
            
                    
                        <b>1.11.</b>
                    
                    Windows系统
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../Windows/cmd命令.html">
            
                <a href="../Windows/cmd命令.html">
            
                    
                        <b>1.11.1.</b>
                    
                    cmd命令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../Vim.html">
            
                <a href="../Vim.html">
            
                    
                        <b>1.12.</b>
                    
                    Vim
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../i3WM快捷键.html">
            
                <a href="../i3WM快捷键.html">
            
                    
                        <b>1.13.</b>
                    
                    i3WM快捷键
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../ADB命令.html">
            
                <a href="../ADB命令.html">
            
                    
                        <b>1.14.</b>
                    
                    ADB命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../Tmux.html">
            
                <a href="../Tmux.html">
            
                    
                        <b>1.15.</b>
                    
                    Tmux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.16" data-path="../Kindle.html">
            
                <a href="../Kindle.html">
            
                    
                        <b>1.16.</b>
                    
                    Kindle越狱指南
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17" data-path="../Other/">
            
                <a href="../Other/">
            
                    
                        <b>1.17.</b>
                    
                    Other
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.17.1" data-path="../Other/pandoc.html">
            
                <a href="../Other/pandoc.html">
            
                    
                        <b>1.17.1.</b>
                    
                    pandoc
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.2" data-path="../Other/jupyter&reveal.js.html">
            
                <a href="../Other/jupyter&reveal.js.html">
            
                    
                        <b>1.17.2.</b>
                    
                    jupyter & reveal.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.3" data-path="../Other/json.html">
            
                <a href="../Other/json.html">
            
                    
                        <b>1.17.3.</b>
                    
                    json
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.17.4" data-path="../Other/Reveal_js.html">
            
                <a href="../Other/Reveal_js.html">
            
                    
                        <b>1.17.4.</b>
                    
                    Reveal_js
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Linux Shell</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-anchor"></i><ul><li><a href="#tips">1. Tips</a></li><li><a href="#&#x8C03;&#x7528;&#x5916;&#x90E8;&#x547D;&#x4EE4;">2. &#x8C03;&#x7528;&#x5916;&#x90E8;&#x547D;&#x4EE4;</a></li><li><a href="#&#x4F7F;&#x7528;&#x53D8;&#x91CF;">3. &#x4F7F;&#x7528;&#x53D8;&#x91CF;</a></li><li><a href="#echo">4. echo</a></li><li><a href="#printf">5. printf</a></li><li><a href="#exec&#x53C2;&#x8003;&#x5730;&#x5740;">6. exec(&#x53C2;&#x8003;&#x5730;&#x5740;)</a></li><li><a href="#read">7. read</a></li><li><a href="#let">8. let</a></li><li><a href="#locate">9. locate</a></li><li><a href="#declare--typeset">10. declare &amp; typeset</a></li><li><a href="#string">11. string</a></li><li><a href="#&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x66FF;&#x6362;">12. &#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x66FF;&#x6362;</a></li><li><a href="#&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x548C;&#x5220;&#x9664;">13. &#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x548C;&#x5220;&#x9664;</a></li><li><a href="#array">14. array</a></li><li><a href="#trap&#x4FE1;&#x53F7;&#x6355;&#x6349;">15. trap&#x4FE1;&#x53F7;&#x6355;&#x6349;</a></li><li><a href="#&#x591A;&#x884C;&#x6CE8;&#x91CA;">16. &#x591A;&#x884C;&#x6CE8;&#x91CA;</a></li><li><a href="#&#x4F20;&#x9012;&#x53C2;&#x6570;">17. &#x4F20;&#x9012;&#x53C2;&#x6570;</a></li><li><a href="#&#x91CD;&#x5B9A;&#x5411;">18. &#x91CD;&#x5B9A;&#x5411;</a></li><li><a href="#shell&#x4E2D;&#x7684;&#x4F7F;&#x7528;">19. shell&#x4E2D;[]&#x7684;&#x4F7F;&#x7528;</a></li><li><a href="#shell&#x57FA;&#x672C;&#x8FD0;&#x7B97;&#x7B26;">20. shell&#x57FA;&#x672C;&#x8FD0;&#x7B97;&#x7B26;</a></li><li><a href="#test">21. test</a></li><li><a href="#&#x6D41;&#x7A0B;&#x63A7;&#x5236;">22. &#x6D41;&#x7A0B;&#x63A7;&#x5236;</a></li><li><a href="#shell&#x51FD;&#x6570;">23. shell&#x51FD;&#x6570;</a></li><li><a href="#&#x5E93;&#x6587;&#x4EF6;">24. &#x5E93;&#x6587;&#x4EF6;</a></li><li><a href="#&#x6587;&#x4EF6;&#x641C;&#x7D22;">25. &#x6587;&#x4EF6;&#x641C;&#x7D22;</a></li><li><a href="#&#x5176;&#x4ED6;">26. &#x5176;&#x4ED6;</a></li><li><a href="#&#x6587;&#x4EF6;&#x5904;&#x7406;&#x4E09;&#x5251;&#x5BA2;">27. &#x6587;&#x4EF6;&#x5904;&#x7406;&#x4E09;&#x5251;&#x5BA2;</a></li></ul></div><a href="#tips" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><blockquote>
<p><strong>This is Linux_shell StudyNote.</strong></p>
</blockquote>
<h1 id="tips"><a name="tips" class="anchor-navigation-ex-anchor" href="#tips"><i class="fa fa-link" aria-hidden="true"></i></a>1. Tips</h1>
<ul>
<li>&#x4F7F;&#x7528;<code>sh -x test.sh</code>&#x53EF;&#x4EE5;&#x67E5;&#x770B;shell&#x7684;&#x6267;&#x884C;&#x6B65;&#x9AA4;&#xFF0C;&#x4F7F;&#x7528;<code>sh -n test.sh</code>&#x53EF;&#x4EE5;&#x7B80;&#x5355;&#x68C0;&#x67E5;shell&#x7684;&#x8BED;&#x6CD5;&#x9519;&#x8BEF;</li>
<li><p><code>nohup</code>&#x5C06;&#x547D;&#x4EE4;&#x653E;&#x4E8E;&#x540E;&#x53F0;&#x6267;&#x884C;&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;<code>nohup sh test.sh &amp;</code>&#xFF0C;&#x6267;&#x884C;&#x547D;&#x4EE4;&#x7684;&#x540C;&#x65F6;&#xFF0C;&#x5728;&#x5BB6;&#x76EE;&#x5F55;&#x4F1A;&#x751F;&#x6210;&#x4E00;&#x4E2A;nohup.out&#x7684;&#x6587;&#x4EF6;&#x6765;&#x63A5;&#x6536;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>tail -f nohup.out</code>&#x6765;&#x5B9E;&#x65F6;&#x67E5;&#x770B;&#x8F93;&#x51FA;&#x5185;&#x5BB9;</p>
<h1 id="&#x8C03;&#x7528;&#x5916;&#x90E8;&#x547D;&#x4EE4;"><a name="&#x8C03;&#x7528;&#x5916;&#x90E8;&#x547D;&#x4EE4;" class="anchor-navigation-ex-anchor" href="#&#x8C03;&#x7528;&#x5916;&#x90E8;&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x8C03;&#x7528;&#x5916;&#x90E8;&#x547D;&#x4EE4;</h1>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token variable"><span class="token variable">`</span><span class="token builtin class-name">command</span><span class="token variable">`</span></span>&#x6216;&#x8005;&#x4F7F;&#x7528;<span class="token variable"><span class="token variable">$(</span><span class="token builtin class-name">command</span><span class="token variable">)</span></span>
<span class="token comment"># &#x7B97;&#x6570;&#x8FD0;&#x7B97;</span>
<span class="token variable"><span class="token variable">$((</span> <span class="token variable">))</span></span>  <span class="token comment"># &#x7528;&#x4E8E;&#x6574;&#x6570;&#x8FD0;&#x7B97;&#xFF0C;&#x5305;&#x62EC;&#x52A0;&#x51CF;&#x4E58;&#x9664;&#xFF0C;&#x5F15;&#x7528;&#x53D8;&#x91CF;&#x65F6;&#x53EF;&#x4E0D;&#x52A0;`$`&#x7B26;&#x53F7;</span>
<span class="token variable"><span class="token punctuation">((</span>num<span class="token operator">++</span><span class="token operator">/</span><span class="token operator">--</span><span class="token punctuation">))</span></span>  <span class="token comment"># &#x53EF;&#x4EE5;&#x7528;&#x6765;&#x8FDB;&#x884C;&#x81EA;&#x589E;&#x6216;&#x8005;&#x81EA;&#x51CF;&#x64CD;&#x4F5C;</span>
</code></pre>
</li>
</ul>
<h1 id="&#x4F7F;&#x7528;&#x53D8;&#x91CF;"><a name="&#x4F7F;&#x7528;&#x53D8;&#x91CF;" class="anchor-navigation-ex-anchor" href="#&#x4F7F;&#x7528;&#x53D8;&#x91CF;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x4F7F;&#x7528;&#x53D8;&#x91CF;</h1>
<ul>
<li><pre class="language-"><code class="lang-shell">$&#x53D8;&#x91CF;&#x540D;&#x79F0;    &#x6216;&#x8005;&#x4F7F;&#x7528;    <span class="token variable">${&#x53D8;&#x91CF;&#x540D;&#x79F0;}</span>
</code></pre>
</li>
<li><p>&#x8BBE;&#x7F6E;&#x53D8;&#x91CF;&#x4E3A;&#x53EA;&#x8BFB;<code>readonly &#x53D8;&#x91CF;&#x540D;&#x79F0;</code></p>
</li>
<li><p>&#x4E00;&#x822C;&#x5728;shell&#x4E2D;&#x53D8;&#x91CF;&#x4F1A;&#x88AB;&#x58F0;&#x660E;&#x6210;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF0C;&#x4F7F;&#x7528;<code>local</code>&#x5173;&#x952E;&#x5B57;&#x53EF;&#x4EE5;&#x5C06;&#x53D8;&#x91CF;&#x5B9A;&#x4E49;&#x4E3A;&#x5C40;&#x90E8;&#x53D8;&#x91CF;&#xFF0C;&#x5982;&#x679C;&#x51FD;&#x6570;&#x5185;&#x5916;&#x5B58;&#x5728;&#x540C;&#x540D;&#x53D8;&#x91CF;&#xFF0C;&#x5219;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7684;&#x53D8;&#x91CF;&#x5C06;&#x4F1A;&#x8986;&#x76D6;&#x5916;&#x90E8;&#x53D8;&#x91CF;</p>
</li>
</ul>
<h1 id="echo"><a name="echo" class="anchor-navigation-ex-anchor" href="#echo"><i class="fa fa-link" aria-hidden="true"></i></a>4. echo</h1>
<ul>
<li><p>echo&#x53EF;&#x52A0;&#x591A;&#x4E2A;&#x53D8;&#x91CF;&#x53C2;&#x6570;,&#x5982;:<code>echo $str1 $str2</code></p>
</li>
<li><p>&#x539F;&#x6837;&#x8F93;&#x51FA;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x4E0D;&#x8FDB;&#x884C;&#x8F6C;&#x4E49;&#x6216;&#x53D6;&#x53D8;&#x91CF;(&#x7528;&#x5355;&#x5F15;&#x53F7;)<code>echo &apos;$name\&quot;&apos;</code>==&gt;$name\&quot;</p>
</li>
<li><p>echo&#x6700;&#x597D;&#x4F7F;&#x7528;&#x53CC;&#x5F15;&#x53F7;</p>
</li>
<li><p>echo&#x8F93;&#x51FA;<code>ANSI</code>&#x5E26;&#x989C;&#x8272;&#x6216;&#x8005;&#x7279;&#x6548;&#x7684;&#x6587;&#x5B57;&#xFF0C;&#x53C2;&#x8003;<a href="https://www.jianshu.com/p/d1b4f554e6f1" target="_blank">https://www.jianshu.com/p/d1b4f554e6f1</a></p>
<ul>
<li><blockquote>
<p>&#x8BED;&#x6CD5;&#x683C;&#x5F0F;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash"><span class="token builtin class-name">echo</span> -e <span class="token string">&quot;<span class="token entity" title="\033">\033</span>[3mSome things you want to print out.<span class="token entity" title="\033">\033</span>[0m&quot;</span>
</code></pre>
<p><code>3x</code>&#x4E3A;&#x8868;&#x793A;<strong>&#x524D;&#x666F;&#x989C;&#x8272;</strong>&#x7684;&#x4E00;&#x7EC4;&#x6570;&#x5B57;&#xFF0C;x&#x53D6;&#x503C;&#x4E3A;0&#x5230;7&#xFF0C;&#x5206;&#x522B;&#x4EE3;&#x8868;&#x7684;&#x989C;&#x8272;&#x5982;&#x4E0B;&#xFF1A;
<code>30</code>&#x8868;&#x793A;&#x9ED1;&#x8272;
<code>31</code>&#x8868;&#x793A;&#x7EA2;&#x8272;
<code>32</code>&#x8868;&#x793A;&#x7EFF;&#x8272;
<code>33</code>&#x8868;&#x793A;&#x9EC4;&#x8272;
<code>34</code>&#x8868;&#x793A;&#x84DD;&#x8272;
<code>35</code>&#x8868;&#x793A;&#x7D2B;&#x8272;
<code>36</code>&#x8868;&#x793A;&#x6D45;&#x84DD;&#x8272;
<code>37</code>&#x8868;&#x793A;&#x7070;&#x8272;
<code>033[0m</code>&#x4E3A;ANSI&#x63A7;&#x5236;&#x7801;&#xFF0C;&#x8868;&#x793A;&#x7ED3;&#x675F;&#x8F93;&#x51FA;&#x6709;&#x989C;&#x8272;&#x7684;&#x5B57;&#x7B26;</p>
<hr>
<p><code>4x</code>&#xFF0C;&#x5E38;&#x7528;&#x7684;<strong>&#x80CC;&#x666F;&#x989C;&#x8272;</strong>&#x4E5F;&#x5171;8&#x79CD;&#xFF0C;<code>x</code>&#x53D6;&#x503C;&#x4E3A;0&#x5230;7&#x3002;&#x5E38;&#x7528;&#x80CC;&#x666F;&#x8272;&#x5982;&#x4E0B;&#xFF1A;
<code>40</code>&#x8868;&#x793A;&#x80CC;&#x666F;&#x4E3A;&#x9ED1;&#x8272;
<code>41</code>&#x8868;&#x793A;&#x80CC;&#x666F;&#x4E3A;&#x7EA2;&#x8272;
<code>42</code>&#x8868;&#x793A;&#x80CC;&#x666F;&#x4E3A;&#x7EFF;&#x8272;
<code>43</code>&#x8868;&#x793A;&#x80CC;&#x666F;&#x4E3A;&#x9EC4;&#x8272;
<code>44</code>&#x8868;&#x793A;&#x80CC;&#x666F;&#x4E3A;&#x84DD;&#x8272;
<code>45</code>&#x8868;&#x793A;&#x80CC;&#x666F;&#x4E3A;&#x7D2B;&#x8272;
<code>46</code>&#x8868;&#x793A;&#x80CC;&#x666F;&#x4E3A;&#x6D45;&#x84DD;&#x8272;
<code>47</code>&#x8868;&#x793A;&#x80CC;&#x666F;&#x4E3A;&#x7070;&#x767D;&#x8272;</p>
<p>&#x6DF7;&#x5408;&#x4F7F;&#x7528;&#x793A;&#x4F8B;</p>
<pre class="language-"><code class="lang-bash"><span class="token builtin class-name">echo</span> -e <span class="token string">&quot;<span class="token entity" title="\033">\033</span>[47;31mHELLO<span class="token entity" title="\033">\033</span>[0m&quot;</span>
</code></pre>
<hr>
<p> &#x5176;&#x5B83;&#x5E38;&#x7528;&#x7684;ANSI&#x63A7;&#x5236;&#x7801;</p>
<p><code>\033[1m</code>&#x8BA9;&#x8F93;&#x51FA;&#x7684;&#x5B57;&#x7B26;&#x9AD8;&#x4EAE;&#x663E;&#x5F0F;
<code>\033[3m</code>&#x8F93;&#x51FA;&#x659C;&#x4F53;&#x5B57;
<code>\033[4m</code>&#x7ED9;&#x8F93;&#x51FA;&#x7684;&#x5B57;&#x7B26;&#x52A0;&#x4E0A;&#x4E0B;&#x5212;&#x7EBF;
<code>\033[5m</code>&#x8BA9;&#x8F93;&#x51FA;&#x7684;&#x5B57;&#x7B26;&#x95EA;&#x70C1;&#x663E;&#x5F0F;
<code>\033[7m</code>&#x8BBE;&#x7F6E;&#x53CD;&#x663E;&#x6548;&#x679C;&#xFF0C;&#x5373;&#x628A;&#x80CC;&#x666F;&#x8272;&#x548C;&#x5B57;&#x4F53;&#x989C;&#x8272;&#x53CD;&#x8FC7;&#x6765;&#x663E;&#x793A;</p>
</blockquote>
</li>
</ul>
</li>
</ul>
<h1 id="printf"><a name="printf" class="anchor-navigation-ex-anchor" href="#printf"><i class="fa fa-link" aria-hidden="true"></i></a>5. printf</h1>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token builtin class-name">printf</span> <span class="token string">&quot;%-10s %-8s %-4.2f<span class="token entity" title="\n">\n</span>&quot;</span> &#x90ED;&#x9756; &#x7537; <span class="token number">66.1234</span> 
<span class="token comment">#  &#x8F93;&#x51FA;:&#x90ED;&#x9756;     &#x7537;      66.12</span>

<span class="token comment"># &#x683C;&#x5F0F;&#x66FF;&#x4EE3;&#x7B26;</span>
<span class="token variable"><span class="token variable">`</span>%-10s<span class="token variable">`</span></span>,<span class="token variable"><span class="token variable">`</span>-<span class="token variable">`</span></span>&#x4EE3;&#x8868;&#x5DE6;&#x5BF9;&#x9F50;<span class="token punctuation">(</span>&#x6CA1;&#x6709;&#x5219;&#x662F;&#x53F3;&#x5BF9;&#x9F50;<span class="token punctuation">)</span>,<span class="token variable"><span class="token variable">`</span>10s<span class="token variable">`</span></span>&#x4EE3;&#x8868;10&#x4E2A;&#x5BBD;&#x5EA6;&#x5B57;&#x7B26;,<span class="token variable"><span class="token variable">`</span>.2<span class="token variable">`</span></span>&#x4EE3;&#x8868;&#x4FDD;&#x7559;&#x4E24;&#x4F4D;&#x5C0F;&#x6570;
<span class="token variable"><span class="token variable">`</span>%c<span class="token variable">`</span></span>&#x540E;&#x52A0;&#x5B57;&#x7B26;&#x4E32;<span class="token punctuation">(</span>&#x7B2C;&#x4E00;&#x4E2A;<span class="token punctuation">)</span>&#x6216;&#x8005;&#x5B57;&#x7B26;
</code></pre>
</li>
</ul>
</li>
</ul>
<h1 id="exec&#x53C2;&#x8003;&#x5730;&#x5740;"><a name="exec&#x53C2;&#x8003;&#x5730;&#x5740;" class="anchor-navigation-ex-anchor" href="#exec&#x53C2;&#x8003;&#x5730;&#x5740;"><i class="fa fa-link" aria-hidden="true"></i></a>6. exec(&#x53C2;&#x8003;&#x5730;&#x5740;)</h1>
<ul>
<li><p>shell&#x7684;&#x5185;&#x5EFA;&#x547D;&#x4EE4;exec&#x5C06;&#x5E76;&#x4E0D;&#x542F;&#x52A8;&#x65B0;&#x7684;shell&#xFF0C;&#x800C;&#x662F;&#x7528;&#x8981;&#x88AB;&#x6267;&#x884C;&#x547D;&#x4EE4;&#x66FF;&#x6362;&#x5F53;&#x524D;&#x7684;shell&#x8FDB;&#x7A0B;&#xFF0C;&#x5E76;&#x4E14;&#x5C06;&#x8001;&#x8FDB;&#x7A0B;&#x7684;&#x73AF;&#x5883;&#x6E05;&#x7406;&#x6389;&#xFF0C;&#x800C;&#x4E14;exec&#x547D;&#x4EE4;&#x540E;&#x7684;&#x5176;&#x5B83;&#x547D;&#x4EE4;&#x5C06;&#x4E0D;&#x518D;&#x6267;&#x884C;&#xFF0C;&#x4E0D;&#x8FC7;&#xFF0C;&#x8981;&#x6CE8;&#x610F;&#x4E00;&#x4E2A;&#x4F8B;&#x5916;&#xFF0C;&#x5F53;exec&#x547D;&#x4EE4;&#x6765;&#x5BF9;&#x6587;&#x4EF6;&#x63CF;&#x8FF0;&#x7B26;&#x64CD;&#x4F5C;&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x5C31;&#x4E0D;&#x4F1A;&#x66FF;&#x6362;shell&#xFF0C;&#x800C;&#x4E14;&#x64CD;&#x4F5C;&#x5B8C;&#x6210;&#x540E;&#xFF0C;&#x8FD8;&#x4F1A;&#x7EE7;&#x7EED;&#x6267;&#x884C;&#x63A5;&#x4E0B;&#x6765;&#x7684;&#x547D;&#x4EE4;&#x3002;</p>
</li>
<li><p>&#x5728;shell&#x4E2D;&#x7684;&#x4E24;&#x79CD;&#x7528;&#x6CD5;</p>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token number">1</span>.  <span class="token builtin class-name">exec</span> &#x547D;&#x4EE4; <span class="token punctuation">;</span>&#x547D;&#x4EE4;&#x4EE3;&#x66FF;shell&#x7A0B;&#x5E8F;&#xFF0C;&#x547D;&#x4EE4;&#x9000;&#x51FA;&#xFF0C;shell &#x9000;&#x51FA;&#xFF1B;&#x6BD4;&#x5982; <span class="token builtin class-name">exec</span> <span class="token function">ls</span>
<span class="token number">2</span>.  <span class="token builtin class-name">exec</span> &#x6587;&#x4EF6;&#x91CD;&#x5B9A;&#x5411;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;&#x6587;&#x4EF6;&#x7684;&#x91CD;&#x5B9A;&#x5411;&#x5C31;&#x770B;&#x4E3A;&#x662F;shell&#x7A0B;&#x5E8F;&#x7684;&#x6587;&#x4EF6;&#x91CD;&#x5B9A;&#x5411; &#x6BD4;&#x5982; <span class="token builtin class-name">exec</span> <span class="token operator"><span class="token file-descriptor important">5</span>&gt;</span>/home/suofeiya/test_dir/test<span class="token punctuation">;</span> <span class="token comment"># &#x4F4D;&#x7F6E;&#x5728;/dev/fd&#x4E2D;</span>
<span class="token function">cat</span> /home/suofeiya/test_dir/test
<span class="token builtin class-name">exec</span> <span class="token operator"><span class="token file-descriptor important">5</span>&gt;&amp;</span>-    <span class="token comment"># &#x53D6;&#x6D88;&#x8BBE;&#x5907;5</span>
</code></pre>
</li>
</ul>
</li>
<li><p>&#x4E0E;source&#x7684;&#x5F02;&#x540C;&#x70B9;&#xFF1A;exec&#x548C;source&#x90FD;&#x662F;&#x5728;&#x7236;&#x8FDB;&#x7A0B;&#x4E2D;&#x76F4;&#x63A5;&#x6267;&#x884C;&#xFF0C;&#x4F46;exec&#x8FD9;&#x4E2A;&#x4E0E;source&#x6709;&#x5F88;&#x5927;&#x7684;&#x533A;&#x522B;&#xFF0C;source&#x662F;&#x6267;&#x884C;shell&#x811A;&#x672C;&#xFF0C;&#x800C;&#x4E14;&#x6267;&#x884C;&#x540E;&#x4F1A;&#x8FD4;&#x56DE;&#x4EE5;&#x524D;&#x7684;shell&#xFF0C;&#x800C;exec&#x5219;&#x662F;&#x8FD0;&#x884C;&#x5B8C;&#x9000;&#x51FA;&#x5F53;&#x524D;shell</p>
<h1 id="read"><a name="read" class="anchor-navigation-ex-anchor" href="#read"><i class="fa fa-link" aria-hidden="true"></i></a>7. read</h1>
<ul>
<li><p>&#x53EF;&#x8BFB;&#x53D6;&#x591A;&#x4E2A;&#x53C2;&#x6570;<code>read &#x53D8;&#x91CF;1 &#x53D8;&#x91CF;2</code></p>
</li>
<li><pre class="language-"><code class="lang-shell"><span class="token builtin class-name">read</span> -p <span class="token string">&quot;&#x8BF7;&#x60A8;&#x4E94;&#x79D2;&#x5185;&#x8F93;&#x5165;&#x60A8;&#x7684;&#x5BC6;&#x7801;(&#x957F;&#x5EA6;&#x9650;&#x5236;6):&quot;</span> -n <span class="token number">6</span> -t <span class="token number">5</span> -s password
<span class="token builtin class-name">echo</span> -e <span class="token string">&quot;<span class="token entity" title="\n">\n</span>your password is <span class="token variable">$password</span>&quot;</span>
-p &#x8F93;&#x5165;&#x63D0;&#x793A;&#x6587;&#x5B57;
-n &#x8F93;&#x5165;&#x5B57;&#x7B26;&#x957F;&#x5EA6;&#x9650;&#x5236;<span class="token punctuation">(</span>&#x8FBE;&#x5230;6&#x4F4D;&#xFF0C;&#x81EA;&#x52A8;&#x7ED3;&#x675F;<span class="token punctuation">)</span>
-t &#x8F93;&#x5165;&#x9650;&#x65F6;
-s &#x9690;&#x85CF;&#x8F93;&#x5165;&#x5185;&#x5BB9;
</code></pre>
</li>
</ul>
</li>
</ul>
<h1 id="let"><a name="let" class="anchor-navigation-ex-anchor" href="#let"><i class="fa fa-link" aria-hidden="true"></i></a>8. let</h1>
<ul>
<li>&#x9664;&#x4E86;&#x652F;&#x6301;<code>expr</code>&#x4E2D;&#x7684;&#x52A0;&#x51CF;&#x4E58;&#x9664;&#x6C42;&#x4F59;&#x5916;&#xFF0C;&#x8FD8;&#x652F;&#x6301;<strong>+=&#xFF0C;-=&#xFF0C;*=&#xFF0C;/=&#xFF0C;%=</strong></li>
</ul>
<h1 id="locate"><a name="locate" class="anchor-navigation-ex-anchor" href="#locate"><i class="fa fa-link" aria-hidden="true"></i></a>9. locate</h1>
<ul>
<li>&#x751F;&#x547D;&#x53D8;&#x91CF;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#xFF0C;&#x53EA;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5185;&#x6709;&#x6548;&#xFF0C;&#x4F8B;&#x5B50;&#xFF1A;<code>locate name=suofeiya</code></li>
</ul>
<h1 id="declare--typeset"><a name="declare--typeset" class="anchor-navigation-ex-anchor" href="#declare--typeset"><i class="fa fa-link" aria-hidden="true"></i></a>10. declare &amp; typeset</h1>
<ul>
<li><p>declare&#x53C2;&#x6570;&#x5217;&#x8868;</p>
<ul>
<li><pre class="language-"><code class="lang-shell">-r  &#x5C06;&#x53D8;&#x91CF;&#x8BBE;&#x7F6E;&#x4E3A;&#x53EA;&#x8BFB;
-i  &#x5C06;&#x53D8;&#x91CF;&#x8BBE;&#x7F6E;&#x4E3A;&#x6574;&#x6570;
-a  &#x5C06;&#x53D8;&#x91CF;&#x8BBE;&#x7F6E;&#x4E3A;&#x6570;&#x7EC4;
-A &#x5C06;&#x53D8;&#x91CF;&#x8BBE;&#x7F6E;&#x6210;&#x5173;&#x8054;&#x6570;&#x7EC4;
-p  &#x663E;&#x793A;&#x53D8;&#x91CF;&#x7684;&#x503C;
-f  &#x663E;&#x793A;&#x6B64;&#x811A;&#x672C;&#x524D;&#x5B9A;&#x4E49;&#x8FC7;&#x7684;&#x6240;&#x6709;&#x51FD;&#x6570;&#x4EE5;&#x53CA;&#x5185;&#x5BB9;
-F  &#x4EC5;&#x663E;&#x793A;&#x6B64;&#x811A;&#x672C;&#x524D;&#x5B9A;&#x4E49;&#x7684;&#x51FD;&#x6570;&#x540D;
-x  &#x5C06;&#x53D8;&#x91CF;&#x8BBE;&#x7F6E;&#x4E3A;&#x5168;&#x5C40;&#x53D8;&#x91CF;
</code></pre>
</li>
</ul>
<h1 id="string"><a name="string" class="anchor-navigation-ex-anchor" href="#string"><i class="fa fa-link" aria-hidden="true"></i></a>11. string</h1>
<ul>
<li><p>&#x83B7;&#x53D6;&#x5B57;&#x7B26;&#x4E32;&#x957F;&#x5EA6;<code>${#str}</code></p>
</li>
<li><p>&#x67E5;&#x627E;&#x5B50;&#x5B57;&#x7B26;&#x4E32;<code>expr index &quot;$str&quot; xy</code>,&#x67E5;&#x627E;&#x5B57;&#x7B26;x/y&#x7684;&#x4F4D;&#x7F6E;</p>
</li>
<li><p>&#x904D;&#x5386;&#x5B57;&#x7B26;&#x4E32;<code>for str in &apos;This is a string&apos;;do echo $str;done;</code></p>
</li>
<li><p>&#x622A;&#x53D6;&#x5B57;&#x7B26;&#x4E32;(&#x5B57;&#x7B26;&#x4E32;&#x5207;&#x7247;)</p>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token assign-left variable">var</span><span class="token operator">=</span>https://suofeiya.pro/mygitbook
<span class="token builtin class-name">echo</span> <span class="token variable">${var<span class="token operator">#</span>*<span class="token operator">/</span><span class="token operator">/</span>}</span>             <span class="token comment"># `#`&#x4E3A;&#x8FD0;&#x7B97;&#x7B26;,&#x5220;&#x9664;&#x5DE6;&#x8FB9;&#x5F00;&#x59CB;&#x5230;`//`&#x7ED3;&#x675F;&#x7684;&#x5B57;&#x7B26;,suofeiya.pro</span>
<span class="token builtin class-name">echo</span> <span class="token variable">${var<span class="token operator">##</span>*<span class="token operator">/</span>}</span>             <span class="token comment"># &#x5220;&#x9664;&#x6700;&#x540E;&#x4E00;&#x4E2A;`/`&#x4E4B;&#x524D;&#x5B57;&#x7B26;,mygitbook</span>
<span class="token builtin class-name">echo</span> <span class="token variable">${var<span class="token operator">%</span><span class="token operator">/</span>*}</span>              <span class="token comment"># `%/*`&#x4ECE;&#x53F3;&#x8FB9;&#x5F00;&#x59CB;&#x5220;&#x9664;`/`&#x53F3;&#x8FB9;&#x5B57;&#x7B26;,https://suofeiya.pro</span>
<span class="token builtin class-name">echo</span> <span class="token variable">${var<span class="token operator">%%</span><span class="token operator">/</span>*}</span>              <span class="token comment"># &#x5220;&#x9664;&#x6700;&#x540E;&#x4E00;&#x4E2A;`/`&#x4E4B;&#x540E;&#x5185;&#x5BB9;</span>
<span class="token builtin class-name">echo</span> <span class="token variable">${var<span class="token operator">:</span>0<span class="token operator">:</span>5}</span>              <span class="token comment"># &#x622A;&#x53D6;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E4B;&#x540E;&#x7684;&#x4E94;&#x4E2A;&#x5B57;&#x7B26;</span>
<span class="token builtin class-name">echo</span> <span class="token variable">${var<span class="token operator">:</span>0}</span>              <span class="token comment"># &#x4ECE;&#x7B2C;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x5F00;&#x59CB;&#x5230;&#x7ED3;&#x675F;</span>
<span class="token builtin class-name">echo</span> <span class="token variable">${var<span class="token operator">:</span>0-13<span class="token operator">:</span>3}</span>              <span class="token comment"># &#x5176;&#x4E2D;&#x7684;`0-7`&#x8868;&#x793A;&#x53F3;&#x8FB9;&#x7B97;&#x8D77;&#x7B2C;&#x4E03;&#x4E2A;&#x5B57;&#x7B26;&#x5F00;&#x59CB;,&#x622A;&#x53D6;3&#x4E2A;&#x5B57;&#x7B26;,pro</span>
<span class="token comment"># &#x603B;&#x7ED3;:`#&#x3001;`## &#x8868;&#x793A;&#x4ECE;&#x5DE6;&#x8FB9;&#x5F00;&#x59CB;&#x5220;&#x9664;&#x3002;&#x4E00;&#x4E2A; # &#x8868;&#x793A;&#x4ECE;&#x5DE6;&#x8FB9;&#x5220;&#x9664;&#x5230;&#x7B2C;&#x4E00;&#x4E2A;&#x6307;&#x5B9A;&#x7684;&#x5B57;&#x7B26;&#xFF1B;&#x4E24;&#x4E2A; # &#x8868;&#x793A;&#x4ECE;&#x5DE6;&#x8FB9;&#x5220;&#x9664;&#x5230;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x6307;&#x5B9A;&#x7684;&#x5B57;&#x7B26;</span>
<span class="token comment"># `%`&#x3001;`%%` &#x8868;&#x793A;&#x4ECE;&#x53F3;&#x8FB9;&#x5F00;&#x59CB;&#x5220;&#x9664;&#x3002;&#x4E00;&#x4E2A; % &#x8868;&#x793A;&#x4ECE;&#x53F3;&#x8FB9;&#x5220;&#x9664;&#x5230;&#x7B2C;&#x4E00;&#x4E2A;&#x6307;&#x5B9A;&#x7684;&#x5B57;&#x7B26;&#xFF1B;&#x4E24;&#x4E2A; % &#x8868;&#x793A;&#x4ECE;&#x5DE6;&#x8FB9;&#x5220;&#x9664;&#x5230;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x6307;&#x5B9A;&#x7684;&#x5B57;&#x7B26;</span>
<span class="token comment"># &#x5220;&#x9664;&#x5305;&#x62EC;&#x4E86;&#x6307;&#x5B9A;&#x7684;&#x5B57;&#x7B26;&#x672C;&#x8EAB;</span>
</code></pre>
</li>
</ul>
</li>
<li><p>&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x66FF;&#x6362;&#x548C;&#x5220;&#x9664;</p>
<ul>
<li><pre class="language-"><code class="lang-bash">

</code></pre>
<h1 id="&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x66FF;&#x6362;"><a name="&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x66FF;&#x6362;" class="anchor-navigation-ex-anchor" href="#&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x66FF;&#x6362;"><i class="fa fa-link" aria-hidden="true"></i></a>12. &#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x66FF;&#x6362;</h1>
<p>${var/PATTERN/SUBSTI}         # &#x67E5;&#x627E;var&#x6240;&#x8868;&#x793A;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#xFF0C;&#x7B2C;&#x4E00;&#x6B21;&#x88AB;PATTERN&#x6240;&#x5339;&#x914D;&#x5230;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5E76;&#x5C06;&#x5176;&#x66FF;&#x6362;&#x4E3A;SUBSTI&#x6240;&#x8868;&#x793A;&#x7684;&#x5B57;&#x7B26;&#x4E32;
${var//PATTERN/SUBSTI}        # &#x67E5;&#x627E;&#x6240;&#x6709;&#x5E76;&#x66FF;&#x6362;</p>
<p>${var/#PATTERN/SUBSTI}        # &#x67E5;&#x627E;&#x884C;&#x9996;&#x4E3A;PATTERN&#x6240;&#x5339;&#x914D;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#xFF0C;&#x5E76;&#x66FF;&#x6362;
${var/%PATTERN/SUBSTI}        # &#x884C;&#x5C3E;...</p>
<h1 id="&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x548C;&#x5220;&#x9664;"><a name="&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x548C;&#x5220;&#x9664;" class="anchor-navigation-ex-anchor" href="#&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x548C;&#x5220;&#x9664;"><i class="fa fa-link" aria-hidden="true"></i></a>13. &#x5B57;&#x7B26;&#x4E32;&#x7684;&#x67E5;&#x627E;&#x548C;&#x5220;&#x9664;</h1>
<p>${var/PATTERN}        # &#x67E5;&#x627E;&#x4EE5;PATTERN&#x6240;&#x5339;&#x914D;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x7684;&#x7B2C;&#x4E00;&#x6B21;&#x5339;&#x914D;&#xFF0C;&#x5E76;&#x5220;&#x9664;
${var//PATTERN}        # &#x67E5;&#x627E;&#x6240;&#x6709;...
${var/#PATTERN}        # &#x67E5;&#x627E;&#x884C;&#x9996;
${var/%PATTERN}        # &#x884C;&#x5C3E;</p>
<pre class="language-"><code>

</code></pre></li>
</ul>
</li>
</ul>
</li>
<li><p>&#x5B57;&#x7B26;&#x4E32;&#x53D8;&#x91CF;&#x7684;&#x7279;&#x6B8A;&#x8D4B;&#x503C;</p>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token variable">${var<span class="token operator">:-</span>VALUE}</span>        <span class="token comment"># &#x5982;&#x679C;var&#x4E3A;&#x7A7A;&#x6216;&#x8005;&#x4E3A;&#x8D4B;&#x503C;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;VALUE&#xFF0C;&#x5426;&#x5219;&#x8FD4;&#x56DE;var&#x503C;</span>
<span class="token variable">${var<span class="token operator">:=</span>VALUE}</span>        <span class="token comment"># &#x5982;&#x679C;var&#x4E3A;&#x7A7A;&#x6216;&#x8005;&#x4E3A;&#x8D4B;&#x503C;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;VALUE&#xFF0C;&#x5E76;&#x5C06;VALUE&#x8D4B;&#x503C;&#x7ED9;var&#xFF0C;&#x5426;&#x5219;&#x8FD4;&#x56DE;var&#x503C;</span>
<span class="token variable">${var<span class="token operator">:+</span>VALUE}</span>        <span class="token comment"># &#x5982;&#x679C;var&#x4E3A;&#x975E;&#x7A7A;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;VALUE&#xFF0C;&#x76F8;&#x5F53;&#x4E8E;&#x975E;&#x7A7A;&#x65F6;&#x66FF;&#x6362;</span>
<span class="token variable">${var<span class="token operator">:?</span>ERROR_INFO}</span>        <span class="token comment"># &#x5982;&#x679C;var&#x4E3A;&#x7A7A;&#x6216;&#x8005;&#x672A;&#x8D4B;&#x503C;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;ERROR_INFO&#x9519;&#x8BEF;&#x63D0;&#x793A;&#xFF0C;&#x5426;&#x5219;&#x8FD4;&#x56DE;var&#x503C;</span>
</code></pre>
</li>
<li><p>&#x5B57;&#x7B26;&#x5927;&#x5C0F;&#x8F6C;&#x6362;</p>
<ul>
<li><pre class="language-"><code class="lang-bash">  <span class="token variable">${var<span class="token operator">^^</span>}</span>        <span class="token comment"># &#x5C06;var&#x53D8;&#x91CF;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x5C0F;&#x5199;&#x5B57;&#x7B26;&#x8F6C;&#x6362;&#x6210;&#x5927;&#x5199;</span>
<span class="token variable">${var<span class="token operator">,,</span>}</span>         <span class="token comment"># &#x5C06;var&#x53D8;&#x91CF;&#x5B57;&#x7B26;&#x4E32;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x5927;&#x5199;&#x5B57;&#x7B26;&#x8F6C;&#x6362;&#x6210;&#x5927;&#x5199;</span>
</code></pre>
</li>
</ul>
</li>
<li><p>&#x5B57;&#x7B26;&#x4E32;&#x6BD4;&#x8F83;</p>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token variable"><span class="token variable">`</span><span class="token operator">=</span><span class="token variable">`</span></span>,<span class="token variable"><span class="token variable">`</span><span class="token operator">!=</span><span class="token variable">`</span></span>  &#x4E24;&#x5B57;&#x7B26;&#x4E32;&#x76F8;&#x540C;,&#x4E0D;&#x76F8;&#x540C;
<span class="token variable"><span class="token variable">`</span>-z<span class="token variable">`</span></span> &#x68C0;&#x6D4B;&#x5B57;&#x7B26;&#x4E32;&#x957F;&#x5EA6;&#x662F;&#x5426;&#x4E3A;0&#xFF0C;&#x4E3A;0&#x8FD4;&#x56DE; <span class="token boolean">true</span>
<span class="token variable"><span class="token variable">`</span>-n<span class="token variable">`</span></span> &#x4E0E;<span class="token variable"><span class="token variable">`</span>-z<span class="token variable">`</span></span>&#x76F8;&#x53CD;
<span class="token variable"><span class="token variable">`</span>$<span class="token variable">`</span></span>  &#x68C0;&#x6D4B;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x5426;&#x4E3A;&#x7A7A;&#xFF0C;&#x4E0D;&#x4E3A;&#x7A7A;&#x8FD4;&#x56DE; <span class="token boolean">true</span>
    <span class="token assign-left variable">a</span><span class="token operator">=</span><span class="token string">&quot;abcd&quot;</span>
    <span class="token punctuation">[</span> <span class="token variable">$a</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; <span class="token boolean">true</span>
</code></pre>
</li>
</ul>
</li>
</ul>
<h1 id="array"><a name="array" class="anchor-navigation-ex-anchor" href="#array"><i class="fa fa-link" aria-hidden="true"></i></a>14. array</h1>
<ul>
<li><p>&#x6570;&#x7EC4;&#x58F0;&#x660E;&#xFF1A;&#x58F0;&#x660E;&#x7D22;&#x5F15;&#x6570;&#x7EC4;&#xFF0C;<code>declare -a ARRAY_NAME</code>&#xFF1B;&#x58F0;&#x660E;&#x5173;&#x8054;&#x6570;&#x7EC4;&#xFF0C;<code>declare -A ARRAY_NAME</code>&#xFF0C;&#x4F8B;&#x5982;&#xFF1A;<code>ARRAY_NAME([index_name1]=&quot;value1&quot; [index_name2]=&quot;value2&quot;)</code></p>
</li>
<li><p>&#x6570;&#x7EC4;&#x4E2D;&#x5143;&#x7D20;&#x7684;&#x8D4B;&#x503C;&#x65B9;&#x5F0F;&#xFF1A;</p>
</li>
<li><blockquote>
<p>&#xFF08;1&#xFF09;&#x4E00;&#x6B21;&#x53EA;&#x8D4B;&#x503C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;&#xFF1A;</p>
<p>&#x200B;            ARRAY_NAME[INDEX]=VALUE</p>
<p>&#xFF08;2&#xFF09;&#x4E00;&#x6B21;&#x8D4B;&#x503C;&#x5168;&#x90E8;&#x5143;&#x7D20;&#xFF1A;</p>
<p>&#x200B;            ARRAY_NAME={&quot;VALUE1&quot; &quot;VALUE2&quot; ...}</p>
<p>&#xFF08;3&#xFF09;&#x53EA;&#x8D4B;&#x503C;&#x7279;&#x5B9A;&#x5143;&#x7D20;&#xFF1A;</p>
<p>&#x200B;            ARRAY_NAME=([0]=&quot;VALUE&quot; [23]=&quot;VALUE&quot; ...)</p>
<p>&#x6CE8;&#x610F;&#xFF1A;bash&#x652F;&#x6301;&#x7A00;&#x758F;&#x683C;&#x5F0F;&#x7684;&#x6570;&#x7EC4;</p>
<p>&#xFF08;4&#xFF09;&#x4F7F;&#x7528;read&#x4ECE;&#x952E;&#x76D8;&#x4EA4;&#x4E92;&#x5F0F;&#x8BFB;&#x5165;</p>
<p>&#x200B;            read -a ARRAY_NAME</p>
</blockquote>
</li>
<li><p>&#x8BFB;&#x53D6;&#x6570;&#x7EC4;</p>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># &#x6309;&#x7167;&#x7D22;&#x5F15;&#x83B7;&#x53D6;&#xFF0C;&#x4E0D;&#x52A0;&#x4E0B;&#x6807;&#x9ED8;&#x8BA4;&#x53EA;&#x8BFB;&#x53D6;&#x7B2C;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</span>
<span class="token variable">${array<span class="token punctuation">[</span>&#x4E0B;&#x6807;<span class="token punctuation">]</span>}</span>
<span class="token comment"># &#x5229;&#x7528;@&#x83B7;&#x53D6;&#x6570;&#x7EC4;&#x6240;&#x6709;&#x5143;&#x7D20;</span>
<span class="token variable">${array<span class="token punctuation">[</span>@<span class="token punctuation">]</span>}</span>  
<span class="token comment"># &#x904D;&#x5386;&#x6570;&#x7EC4;1</span>
<span class="token keyword">for</span> <span class="token for-or-select variable">i</span> <span class="token keyword">in</span> <span class="token variable">${my_arry<span class="token punctuation">[</span>@<span class="token punctuation">]</span>}</span><span class="token punctuation">;</span><span class="token keyword">do</span> <span class="token builtin class-name">echo</span> <span class="token variable">$i</span> <span class="token keyword">done</span>
<span class="token comment"># &#x904D;&#x5386;&#x6570;&#x7EC4;2</span>
<span class="token assign-left variable">j</span><span class="token operator">=</span><span class="token number">0</span> <span class="token keyword">while</span> <span class="token punctuation">[</span> <span class="token variable">$j</span> -lt <span class="token variable">${<span class="token operator">#</span>my_arry<span class="token punctuation">[</span>@<span class="token punctuation">]</span>}</span> <span class="token punctuation">]</span> <span class="token keyword">do</span>
  <span class="token builtin class-name">echo</span> <span class="token variable">${my_arry<span class="token punctuation">[</span>$j<span class="token punctuation">]</span>}</span>
  <span class="token builtin class-name">let</span> <span class="token string">&quot;j++&quot;</span> <span class="token comment"># &#x81EA;&#x589E;,&#x53CC;&#x5F15;&#x53F7;&#x53EF;&#x52A0;&#x53EF;&#x4E0D;&#x52A0;,&#x7B49;&#x4EF7;&#x4E8E;`let j+=1`,&#x8FD8;&#x53EF;&#x4EE5;`a=$[$a+1]`&#x8FD8;&#x53EF;&#x4EE5;`j=`expr $j + 1``&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;`((j++))``&#x6216;&#x8005;`$((j++))`&#x6765;&#x5B9E;&#x73B0;</span>
<span class="token keyword">done</span>
</code></pre>
</li>
</ul>
</li>
</ul>
</li>
<li><p>&#x6570;&#x7EC4;&#x7684;&#x5207;&#x7247;&#xFF1A;<code>${var:offset:number}</code>&#x83B7;&#x53D6;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x5B50;&#x4E32;&#xFF0C;offset&#x8868;&#x793A;&#x504F;&#x79FB;&#xFF0C;number&#x8868;&#x793A;&#x504F;&#x79FB;&#x91CF;&#x3002;&#x6B64;&#x5916;<code>${var: -length}</code>&#xFF0C;&#x53D6;&#x5B57;&#x7B26;&#x4E32;&#x6700;&#x53F3;&#x4FA7;&#x7684;&#x51E0;&#x4E2A;&#x5B57;&#x7B26;&#xFF0C;&#x6CE8;&#x610F;&#xFF1A;<code>-</code>&#x53F7;&#x524D;&#x65B9;&#x6709;&#x7A7A;&#x683C;</p>
</li>
<li><p>&#x6570;&#x7EC4;&#x5143;&#x7D20;&#x7684;&#x66FF;&#x6362;&#xFF1A;<code>${array[*]/old/new}</code>&#xFF0C;&#x52A0;&#x4E0A;&#x53CC;&#x659C;&#x6760;&#x4EE3;&#x8868;&#x5168;&#x90E8;&#x66FF;&#x6362;<code>${array[*]//old/new}</code>&#xFF0C;&#x6CE8;&#x610F;&#xFF1A;<strong>&#x53EA;&#x9488;&#x5BF9;&#x6570;&#x7EC4;&#x5168;&#x90E8;&#xFF0C;&#x800C;&#x4E0D;&#x53EA;&#x9488;&#x5BF9;&#x67D0;&#x4E00;&#x4E2A;&#x5143;&#x7D20;</strong></p>
</li>
<li><p>&#x83B7;&#x53D6;&#x6570;&#x7EC4;&#x957F;&#x5EA6;<code>${#array[@/*]}</code>,&#x83B7;&#x53D6;&#x5355;&#x4E2A;&#x5143;&#x7D20;&#x7684;&#x957F;&#x5EA6;<code>${#array[&#x4E0B;&#x6807;]}</code></p>
</li>
<li><p>&#x5411;&#x975E;&#x7A00;&#x758F;&#x6570;&#x7EC4;&#x4E2D;&#x8FFD;&#x52A0;&#x5143;&#x7D20;<code>ARRAY_NAME[${ARRAY_NAME[*]}]</code></p>
</li>
<li><p><code>unset</code>&#x6E05;&#x9664;&#x5143;&#x7D20;&#xFF0C;<code>unset array[index]</code>&#x5220;&#x9664;&#x67D0;&#x4E2A;&#x5143;&#x7D20;&#xFF0C;<code>unset array</code>&#x5220;&#x9664;&#x6574;&#x4E2A;&#x6570;&#x7EC4;&#xFF0C;&#x6CE8;&#x610F;&#xFF1A;shell&#x4E2D;&#x5220;&#x9664;&#x67D0;&#x4E2A;&#x5143;&#x7D20;&#x540E;&#xFF0C;<strong>&#x4F1A;&#x4FDD;&#x7559;&#x539F;&#x6765;&#x7684;&#x5143;&#x7D20;&#x7684;index&#x4E0B;&#x6807;</strong></p>
</li>
</ul>
<h1 id="trap&#x4FE1;&#x53F7;&#x6355;&#x6349;"><a name="trap&#x4FE1;&#x53F7;&#x6355;&#x6349;" class="anchor-navigation-ex-anchor" href="#trap&#x4FE1;&#x53F7;&#x6355;&#x6349;"><i class="fa fa-link" aria-hidden="true"></i></a>15. trap&#x4FE1;&#x53F7;&#x6355;&#x6349;</h1>
<ul>
<li><p>&#x53C2;&#x8003;&#xFF1A;<a href="https://blog.csdn.net/sinceNow/article/details/86294081" target="_blank">https://blog.csdn.net/sinceNow/article/details/86294081</a></p>
</li>
<li><p>&#x4F7F;&#x7528;&#x683C;&#x5F0F;&#xFF1A;<code>trap &apos;commands&apos; signal-list</code></p>
</li>
<li><p>&#x4FE1;&#x53F7;&#x8BF4;&#x660E;</p>
<ul>
<li><blockquote>
<p>HUP(1)&#x3000;&#x3000;&#x3000;&#x3000;&#x6302;&#x8D77;&#xFF0C;&#x901A;&#x5E38;&#x56E0;&#x7EC8;&#x7AEF;&#x6389;&#x7EBF;&#x6216;&#x7528;&#x6237;&#x9000;&#x51FA;&#x800C;&#x5F15;&#x53D1;
INT(2)&#x3000;&#x3000;&#x3000;&#x3000;&#x4E2D;&#x65AD;&#xFF0C;&#x901A;&#x5E38;&#x56E0;&#x6309;&#x4E0B;Ctrl+C&#x7EC4;&#x5408;&#x952E;&#x800C;&#x5F15;&#x53D1;
QUIT(3)&#x3000;&#x3000;&#x9000;&#x51FA;&#xFF0C;&#x901A;&#x5E38;&#x56E0;&#x6309;&#x4E0B;Ctrl+&#x7EC4;&#x5408;&#x952E;&#x800C;&#x5F15;&#x53D1;
ABRT(6)&#x3000;&#x3000;&#x4E2D;&#x6B62;&#xFF0C;&#x901A;&#x5E38;&#x56E0;&#x67D0;&#x4E9B;&#x4E25;&#x91CD;&#x7684;&#x6267;&#x884C;&#x9519;&#x8BEF;&#x800C;&#x5F15;&#x53D1;
ALRM(14)&#x3000;&#x3000;&#x62A5;&#x8B66;&#xFF0C;&#x901A;&#x5E38;&#x7528;&#x6765;&#x5904;&#x7406;&#x8D85;&#x65F6;
TERM(15)&#x3000;&#x3000;&#x7EC8;&#x6B62;&#xFF0C;&#x901A;&#x5E38;&#x5728;&#x7CFB;&#x7EDF;&#x5173;&#x673A;&#x65F6;&#x53D1;&#x9001;</p>
</blockquote>
</li>
</ul>
</li>
<li><p>&#x793A;&#x4F8B;&#x811A;&#x672C;</p>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token comment"># &#x6267;&#x884C;&#x811A;&#x672C;&#x65F6;&#xFF0C;&#x4F7F;&#x7528;ctrl+c&#x53EF;&#x4EE5;&#x5C06;/tmp/westos&#x4E0B;&#x5EFA;&#x7ACB;&#x7684;&#x6587;&#x4EF6;&#x90FD;&#x5220;&#x9664;&#x6389;</span>
<span class="token comment">#!/bin/bash</span>
<span class="token builtin class-name">trap</span> <span class="token string">&quot;find /tmp -type f -name &quot;</span>westos_*<span class="token string">&quot; | xargs rm -f &amp;&amp; exit &quot;</span> <span class="token number">2</span>

<span class="token keyword">while</span> <span class="token boolean">true</span>
<span class="token keyword">do</span>
    <span class="token function">touch</span> /tmp/westos_<span class="token variable"><span class="token variable">$(</span><span class="token function">date</span> +%F-%N-%M-%S<span class="token variable">)</span></span>
    <span class="token function">sleep</span> <span class="token number">2</span>
    <span class="token function">ls</span> -l /tmp/westos*
<span class="token keyword">done</span>
</code></pre>
</li>
</ul>
</li>
<li><p>&#x53EF;&#x4EE5;&#x5C06;&#x6355;&#x6349;&#x7684;&#x52A8;&#x4F5C;&#x5B9A;&#x4E49;&#x4E3A;&#x51FD;&#x6570;&#xFF0C;&#x4F8B;&#x5982;<code>trap &apos;mytrap&apos; INT</code>&#xFF0C;&#x5176;&#x4E2D;<code>mytrap</code>&#x4E3A;&#x51FD;&#x6570;&#x540D;&#x79F0;</p>
<h1 id="&#x591A;&#x884C;&#x6CE8;&#x91CA;"><a name="&#x591A;&#x884C;&#x6CE8;&#x91CA;" class="anchor-navigation-ex-anchor" href="#&#x591A;&#x884C;&#x6CE8;&#x91CA;"><i class="fa fa-link" aria-hidden="true"></i></a>16. &#x591A;&#x884C;&#x6CE8;&#x91CA;</h1>
<ul>
<li><pre class="language-"><code class="lang-shell">:<span class="token operator">&lt;&lt;</span><span class="token string">EOF
&#x6CE8;&#x91CA;&#x5185;&#x5BB9;...
&#x6CE8;&#x91CA;&#x5185;&#x5BB9;...
&#x6CE8;&#x91CA;&#x5185;&#x5BB9;...
EOF</span>
EOF &#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#x5176;&#x4ED6;&#x7B26;&#x53F7;: &#x4F8B;&#x5982;,<span class="token operator">!</span>&#x7B49;
&#x4E5F;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;&#x4E0D;&#x4F1A;&#x88AB;&#x8C03;&#x7528;&#x7684;&#x51FD;&#x6570;&#x6765;&#x5199;&#x591A;&#x884C;&#x6CE8;&#x91CA;
</code></pre>
</li>
</ul>
<h1 id="&#x4F20;&#x9012;&#x53C2;&#x6570;"><a name="&#x4F20;&#x9012;&#x53C2;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x4F20;&#x9012;&#x53C2;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>17. &#x4F20;&#x9012;&#x53C2;&#x6570;</h1>
<ul>
<li><p><code>$#</code>&#x4F20;&#x9012;&#x5230;shell&#x7684;&#x53C2;&#x6570;&#x4E2A;&#x6570;</p>
</li>
<li><p><code>$*</code>&#x4EE5;&#x5355;&#x4E00;&#x5B57;&#x7B26;&#x4E32;&#x663E;&#x793A;&#x6240;&#x6709;&#x4F20;&#x5411;shell&#x7684;&#x53C2;&#x6570;&#x60C5;&#x51B5;&#x4EE5;<code>&quot;$1 $2 ...&quot;</code>&#x663E;&#x793A;</p>
</li>
<li><p><code>$@</code>&#x4E0E;<code>$*</code>&#x76F8;&#x4F3C;,&#x4F46;&#x662F;&#x8F93;&#x51FA;&#x591A;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;,<code>for i in &quot;$@&quot;;do echo$i done</code>,<code>@/*</code>&#x4E24;&#x8005;&#x90FD;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x83B7;&#x53D6;&#x5230;</p>
</li>
<li><p><code>$$</code>shell&#x5F53;&#x524D;&#x8FDB;&#x7A0B;ID</p>
</li>
<li><p><code>$!</code>&#x540E;&#x53F0;&#x8FD0;&#x884C;&#x7684;&#x6700;&#x540E;&#x4E00;&#x4E2A;&#x8FDB;&#x7A0B;ID</p>
</li>
<li><p><code>$-</code>&#x663E;&#x793A;Shell&#x4F7F;&#x7528;&#x7684;&#x5F53;&#x524D;&#x9009;&#x9879;&#xFF0C;&#x4E0E;<code>set</code>&#x547D;&#x4EE4;&#x529F;&#x80FD;&#x76F8;&#x540C;</p>
</li>
<li><p><code>$?</code>&#x663E;&#x793A;&#x547D;&#x4EE4;&#x6700;&#x540E;&#x7684;&#x9000;&#x51FA;&#x72B6;&#x6001;,&#x4F7F;&#x7528;<code>perror [&#x8FD4;&#x56DE;&#x503C;]</code>&#x6765;&#x67E5;&#x770B;&#x8BE6;&#x7EC6;&#x9000;&#x51FA;&#x72B6;&#x6001;</p>
</li>
</ul>
<h1 id="&#x91CD;&#x5B9A;&#x5411;"><a name="&#x91CD;&#x5B9A;&#x5411;" class="anchor-navigation-ex-anchor" href="#&#x91CD;&#x5B9A;&#x5411;"><i class="fa fa-link" aria-hidden="true"></i></a>18. &#x91CD;&#x5B9A;&#x5411;</h1>
</li>
<li><p><code>n &gt;&amp; m</code>&#x5C06;&#x8F93;&#x51FA;&#x6587;&#x4EF6; m &#x548C; n &#x5408;&#x5E76;</p>
</li>
<li><p><code>n &lt;&amp; m</code>&#x5C06;&#x8F93;&#x5165;&#x6587;&#x4EF6; m &#x548C; n &#x5408;&#x5E76;</p>
</li>
<li><p><code>&lt;&lt; tag</code>&#x5C06;&#x5F00;&#x59CB;&#x6807;&#x8BB0; tag &#x548C;&#x7ED3;&#x675F;&#x6807;&#x8BB0; tag &#x4E4B;&#x95F4;&#x7684;&#x5185;&#x5BB9;&#x4F5C;&#x4E3A;&#x8F93;&#x5165;</p>
</li>
<li><p><code>command1 &lt; infile &gt; outfile</code>&#x540C;&#x65F6;&#x66FF;&#x6362;&#x8F93;&#x5165;&#x548C;&#x8F93;&#x51FA;&#xFF0C;&#x6267;&#x884C;command1&#xFF0C;&#x4ECE;&#x6587;&#x4EF6;infile&#x8BFB;&#x53D6;&#x5185;&#x5BB9;&#xFF0C;&#x7136;&#x540E;&#x5C06;&#x8F93;&#x51FA;&#x5199;&#x5165;&#x5230;outfile&#x4E2D;&#x3002;</p>
</li>
<li><p>&#x6587;&#x4EF6;&#x63CF;&#x8FF0;&#x7B26; 0 &#x901A;&#x5E38;&#x662F;&#x6807;&#x51C6;&#x8F93;&#x5165;&#xFF08;STDIN&#xFF09;&#xFF0C;1 &#x662F;&#x6807;&#x51C6;&#x8F93;&#x51FA;&#xFF08;STDOUT&#xFF09;&#xFF0C;2 &#x662F;&#x6807;&#x51C6;&#x9519;&#x8BEF;&#x8F93;&#x51FA;&#xFF08;STDERR&#xFF09;, &#x4F8B;&#x5982;:&#x5C06;stderr&#x91CD;&#x5B9A;&#x5411;&#x5230;file&#x4F7F;&#x7528;<code>command 2 &gt; file</code>,&#x5408;&#x5E76;stdout&#x548C;stderr&#x5230;file<code>command &gt; file 2&gt;&amp;1</code></p>
</li>
<li><p>Here Document</p>
<ul>
<li><pre class="language-"><code class="lang-bash"> <span class="token function">wc</span> -l <span class="token operator">&lt;&lt;</span> EOF
     &#x7B2C;&#x4E00;&#x884C;
     &#x7B2C;&#x4E8C;&#x884C;
     https://suofeiya.pro
 EOF
</code></pre>
</li>
</ul>
</li>
</ul>
<h1 id="shell&#x4E2D;&#x7684;&#x4F7F;&#x7528;"><a name="shell&#x4E2D;&#x7684;&#x4F7F;&#x7528;" class="anchor-navigation-ex-anchor" href="#shell&#x4E2D;&#x7684;&#x4F7F;&#x7528;"><i class="fa fa-link" aria-hidden="true"></i></a>19. shell&#x4E2D;[]&#x7684;&#x4F7F;&#x7528;</h1>
<ul>
<li>&#x7B97;&#x672F;&#x6BD4;&#x8F83;, &#x6BD4;&#x5982;&#x4E00;&#x4E2A;&#x53D8;&#x91CF;&#x662F;&#x5426;&#x4E3A;0, <code>[ $var -eq 0 ]</code>&#x3002;</li>
<li>&#x6587;&#x4EF6;&#x5C5E;&#x6027;&#x6D4B;&#x8BD5;&#xFF0C;&#x6BD4;&#x5982;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x5B58;&#x5728;&#xFF0C;<code>[ -e $var ]</code>, &#x662F;&#x5426;&#x662F;&#x76EE;&#x5F55;&#xFF0C;<code>[ -d $var ]</code>&#x3002;</li>
<li><p>&#x5B57;&#x7B26;&#x4E32;&#x6BD4;&#x8F83;, &#x6BD4;&#x5982;&#x4E24;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x662F;&#x5426;&#x76F8;&#x540C;&#xFF0C; <code>[[ $var1 = $var2 ]]</code>&#x3002;</p>
<h1 id="shell&#x57FA;&#x672C;&#x8FD0;&#x7B97;&#x7B26;"><a name="shell&#x57FA;&#x672C;&#x8FD0;&#x7B97;&#x7B26;" class="anchor-navigation-ex-anchor" href="#shell&#x57FA;&#x672C;&#x8FD0;&#x7B97;&#x7B26;"><i class="fa fa-link" aria-hidden="true"></i></a>20. shell&#x57FA;&#x672C;&#x8FD0;&#x7B97;&#x7B26;</h1>
</li>
</ul>
<ul>
<li>expr&#x8FD0;&#x7B97;&#x7B26;</li>
<li><p><a href="../home/suofeiya/myGitbook/images/Screenshot_2019-05-24-16-44-20.png" data-lightbox="58eb9c3e-bbde-49bf-8b3e-86c2ff0dff93" data-title="Screenshot_2019-05-24-16-44-20"><img src="../home/suofeiya/myGitbook/images/Screenshot_2019-05-24-16-44-20.png" alt="Screenshot_2019-05-24-16-44-20"></a></p>
</li>
<li><pre class="language-"><code class="lang-shell">  <span class="token assign-left variable">a</span><span class="token operator">=</span><span class="token number">10</span> <span class="token assign-left variable">b</span><span class="token operator">=</span><span class="token number">20</span>
  <span class="token variable"><span class="token variable">`</span><span class="token function">expr</span> $a + $b<span class="token variable">`</span></span> <span class="token comment"># &#x7ED3;&#x679C;30,;&#x52A0;&#x51CF;&#x9664;&#x53D6;&#x4F59;&#x7C7B;&#x4F3C;,&#x4E58;&#x6CD5;&#x9700;&#x8981;&#x8F6C;&#x4E49;&#x5B57;&#x7B26;`\*`&#x624D;&#x80FD;&#x4F7F;&#x7528;</span>
  <span class="token comment"># &#x53EF;&#x4EE5;&#x4F7F;&#x7528;$(expr $a + $b)&#x4EE3;&#x66FF;</span>
  <span class="token assign-left variable">result</span><span class="token operator">=</span>$<span class="token punctuation">[</span>a+b<span class="token punctuation">]</span>  <span class="token comment"># &#x6CE8;&#x610F;:&#x4E0D;&#x80FD;&#x6709;&#x7A7A;&#x683C;</span>
  <span class="token variable"><span class="token variable">`</span><span class="token assign-left variable">a</span><span class="token operator">=</span>$b<span class="token variable">`</span></span>  <span class="token comment"># &#x53D8;&#x91CF;b&#x8D4B;&#x503C;&#x7ED9;a</span>
  <span class="token variable"><span class="token variable">`</span><span class="token punctuation">[</span> $a <span class="token operator">==</span> $b <span class="token punctuation">]</span><span class="token variable">`</span></span> &#x8FD4;&#x56DE; false&#x3002;
</code></pre>
</li>
</ul>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token variable"><span class="token variable">`</span>-ge<span class="token variable">`</span></span> &#x5927;&#x4E8E;&#x7B49;&#x4E8E;    <span class="token punctuation">[</span> <span class="token variable">$a</span> -ge <span class="token variable">$b</span> <span class="token punctuation">]</span>
<span class="token variable"><span class="token variable">`</span>-le<span class="token variable">`</span></span> &#x5C0F;&#x4E8E;&#x7B49;&#x4E8E;    <span class="token punctuation">[</span> <span class="token variable">$a</span> -le <span class="token variable">$b</span> <span class="token punctuation">]</span>
</code></pre>
</li>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># &#x5E03;&#x5C14;&#x8FD0;&#x7B97;&#x7B26;</span>
<span class="token variable"><span class="token variable">`</span>-o<span class="token variable">`</span></span> &#x6216;&#x8FD0;&#x7B97;,&#x6709;&#x4E00;&#x4E2A;&#x4E3A;&#x771F;&#x5219;&#x4E3A;&#x771F;
<span class="token variable"><span class="token variable">`</span>-a<span class="token variable">`</span></span> &#x4E0E;&#x8FD0;&#x7B97;,&#x90FD;&#x4E3A;&#x771F;&#x5219;&#x4E3A;&#x771F;,<span class="token variable"><span class="token variable">`</span><span class="token punctuation">[</span> $a -lt <span class="token number">20</span> -a $b -gt <span class="token number">100</span> <span class="token punctuation">]</span><span class="token variable">`</span></span>
</code></pre>
</li>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># &#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7B26;</span>
<span class="token variable"><span class="token variable">`</span><span class="token operator">&amp;&amp;</span><span class="token variable">`</span></span> &#x903B;&#x8F91;<span class="token variable"><span class="token variable">`</span>AND<span class="token variable">`</span></span>
<span class="token variable"><span class="token variable">`</span><span class="token operator">||</span><span class="token variable">`</span></span>  &#x903B;&#x8F91;<span class="token variable"><span class="token variable">`</span>OR<span class="token variable">`</span></span>
</code></pre>
<ul>
<li><strong>&amp;&amp;</strong>&#x3001;<strong>||</strong>&#x3001;<strong>&lt;</strong> &#x548C; <strong>&gt;</strong> &#x64CD;&#x4F5C;&#x7B26;&#x5B58;&#x5728;&#x4E8E; <strong>[[ ]]</strong> &#x6761;&#x4EF6;&#x5224;&#x65AD;&#x7ED3;&#x6784;&#x4E2D;</li>
<li>[[]] &#x8FD0;&#x7B97;&#x7B26;&#x53EA;&#x662F; [] &#x8FD0;&#x7B97;&#x7B26;&#x7684;&#x6269;&#x5145;&#x3002;&#x80FD;&#x591F;&#x652F;&#x6301; &gt;, &lt; &#x7B26;&#x53F7;&#x8FD0;&#x7B97;&#x4E0D;&#x9700;&#x8981;&#x8F6C;&#x4E49;&#x7B26;&#xFF0C;&#x5B83;&#x8FD8;&#x662F;&#x4EE5;&#x5B57;&#x7B26;&#x4E32;&#x6BD4;&#x8F83;&#x5927;&#x5C0F;&#x3002;&#x91CC;&#x9762;&#x652F;&#x6301;&#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7B26;&#xFF1A;<strong>|| &amp;&amp;</strong> &#xFF0C;&#x4E0D;&#x518D;&#x4F7F;&#x7528; <strong>-a -o</strong>&#x3002;</li>
<li>&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>((exp1 OP exp2))</code>&#x4EE3;&#x66FF;<code>[ exp1 OP exp2 ]</code></li>
<li><strong><code>bc</code>&#x547D;&#x4EE4;&#x7528;&#x6765;&#x8FDB;&#x884C;&#x8FD0;&#x7B97;<code>scale=2</code>&#x4FEE;&#x6539;&#x5C0F;&#x6570;&#x7CBE;&#x5EA6;&#xFF0C;&#x7528;&#x6CD5;`echo &quot;scale=4;50/9&quot; | bc</strong>`</li>
</ul>
</li>
<li><p>&#x6587;&#x4EF6;&#x6D4B;&#x8BD5;&#x8FD0;&#x7B97;&#x7B26;,&#x6765;&#x81EA;<a href="https://www.runoob.com/linux/linux-shell-basic-operators.html" target="_blank">&#x83DC;&#x9E1F;&#x6559;&#x7A0B;&#x6587;&#x4EF6;&#x6D4B;&#x8BD5;&#x8FD0;&#x7B97;&#x7B26;</a></p>
</li>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># &#x64CD;&#x4F5C;&#x7B26;    &#x8BF4;&#x660E;    &#x4E3E;&#x4F8B;</span>
-b <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x662F;&#x5757;&#x8BBE;&#x5907;&#x6587;&#x4EF6;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -b <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; false&#x3002;
-c <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x662F;&#x5B57;&#x7B26;&#x8BBE;&#x5907;&#x6587;&#x4EF6;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -c <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; <span class="token boolean">false</span>    &#x3002;
-d <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x662F;&#x76EE;&#x5F55;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -d <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; false&#x3002;
-f <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x662F;&#x666E;&#x901A;&#x6587;&#x4EF6;&#xFF08;&#x65E2;&#x4E0D;&#x662F;&#x76EE;&#x5F55;&#xFF0C;&#x4E5F;&#x4E0D;&#x662F;&#x8BBE;&#x5907;&#x6587;&#x4EF6;&#xFF09;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -f <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; true&#x3002;
-g <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x8BBE;&#x7F6E;&#x4E86; SGID &#x4F4D;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -g <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; false&#x3002;
-k <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x8BBE;&#x7F6E;&#x4E86;&#x7C98;&#x7740;&#x4F4D;<span class="token punctuation">(</span>Sticky Bit<span class="token punctuation">)</span>&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -k <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; false&#x3002;
-p <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x662F;&#x6709;&#x540D;&#x7BA1;&#x9053;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -p <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; false&#x3002;
-u <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x8BBE;&#x7F6E;&#x4E86; SUID &#x4F4D;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -u <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; false&#x3002;
-r <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x53EF;&#x8BFB;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -r <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; true&#x3002;
-w <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x53EF;&#x5199;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -w <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; true&#x3002;
-x <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x53EF;&#x6267;&#x884C;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -x <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; true&#x3002;
-s <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#x662F;&#x5426;&#x4E3A;&#x7A7A;&#xFF08;&#x6587;&#x4EF6;&#x5927;&#x5C0F;&#x662F;&#x5426;&#x5927;&#x4E8E;0&#xFF09;&#xFF0C;&#x4E0D;&#x4E3A;&#x7A7A;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -s <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; true&#x3002;
-e <span class="token function">file</span>    &#x68C0;&#x6D4B;&#x6587;&#x4EF6;&#xFF08;&#x5305;&#x62EC;&#x76EE;&#x5F55;&#xFF09;&#x662F;&#x5426;&#x5B58;&#x5728;&#xFF0C;&#x5982;&#x679C;&#x662F;&#xFF0C;&#x5219;&#x8FD4;&#x56DE; true&#x3002;    <span class="token punctuation">[</span> -e <span class="token variable">$file</span> <span class="token punctuation">]</span> &#x8FD4;&#x56DE; true&#x3002;
</code></pre>
<h1 id="test"><a name="test" class="anchor-navigation-ex-anchor" href="#test"><i class="fa fa-link" aria-hidden="true"></i></a>21. test</h1>
</li>
<li><p>&#x548C;<code>if</code>&#x662F;&#x597D;&#x642D;&#x6863;,&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x8FDB;&#x884C;&#x6570;&#x503C;,&#x6587;&#x4EF6;,&#x5B57;&#x7B26;&#x4E32;&#x6D4B;&#x8BD5;</p>
</li>
<li><p>Shell&#x8FD8;&#x63D0;&#x4F9B;&#x4E86;&#x4E0E;( -a )&#x3001;&#x6216;( -o )&#x3001;&#x975E;( ! )&#x4E09;&#x4E2A;&#x903B;&#x8F91;&#x64CD;&#x4F5C;&#x7B26;&#x7528;&#x4E8E;&#x5C06;&#x6D4B;&#x8BD5;&#x6761;&#x4EF6;&#x8FDE;&#x63A5;&#x8D77;&#x6765;&#xFF0C;&#x5176;&#x4F18;&#x5148;&#x7EA7;&#x4E3A;&#xFF1A;&quot;!&quot;&#x6700;&#x9AD8;&#xFF0C;&quot;-a&quot;&#x6B21;&#x4E4B;&#xFF0C;&quot;-o&quot;&#x6700;&#x4F4E;</p>
</li>
<li><pre class="language-"><code class="lang-shell"><span class="token keyword">if</span> <span class="token builtin class-name">test</span> -e ./notFile -o -e ./bash
<span class="token keyword">then</span>
    <span class="token builtin class-name">echo</span> <span class="token string">&apos;&#x81F3;&#x5C11;&#x6709;&#x4E00;&#x4E2A;&#x6587;&#x4EF6;&#x5B58;&#x5728;!&apos;</span>
<span class="token keyword">else</span>
    <span class="token builtin class-name">echo</span> <span class="token string">&apos;&#x4E24;&#x4E2A;&#x6587;&#x4EF6;&#x90FD;&#x4E0D;&#x5B58;&#x5728;&apos;</span>
<span class="token keyword">fi</span>
</code></pre>
<h1 id="&#x6D41;&#x7A0B;&#x63A7;&#x5236;"><a name="&#x6D41;&#x7A0B;&#x63A7;&#x5236;" class="anchor-navigation-ex-anchor" href="#&#x6D41;&#x7A0B;&#x63A7;&#x5236;"><i class="fa fa-link" aria-hidden="true"></i></a>22. &#x6D41;&#x7A0B;&#x63A7;&#x5236;</h1>
</li>
</ul>
<ul>
<li><p>if&#x8BED;&#x53E5;</p>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token keyword">if</span> condition1
<span class="token keyword">then</span>
    command1
    command2 <span class="token punctuation">..</span>.
<span class="token keyword">elif</span> condition2
<span class="token keyword">then</span>
    command3
<span class="token keyword">else</span>
    command4
<span class="token keyword">if</span>

<span class="token comment"># &#x5199;&#x6210;&#x4E00;&#x884C;&#xFF0C;&#x9002;&#x5408;&#x4E0E;terminal&#x7EC8;&#x7AEF;&#x4F7F;&#x7528;</span>
<span class="token keyword">if</span> <span class="token punctuation">[</span> <span class="token variable"><span class="token variable">$(</span><span class="token function">ps</span> -ef <span class="token operator">|</span> <span class="token function">grep</span> -c <span class="token string">&quot;ssh&quot;</span><span class="token variable">)</span></span> -gt <span class="token number">1</span> <span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token keyword">then</span> <span class="token builtin class-name">echo</span> <span class="token string">&quot;true&quot;</span><span class="token punctuation">;</span> <span class="token keyword">fi</span>
</code></pre>
</li>
</ul>
</li>
</ul>
<ul>
<li><p>for&#x8BED;&#x53E5;</p>
<ul>
<li><pre class="language-"><code class="lang-shell">  <span class="token keyword">for</span> <span class="token for-or-select variable">var</span> <span class="token keyword">in</span> item1 item2 <span class="token punctuation">..</span>.
  <span class="token keyword">do</span>
      command1
      command2 <span class="token punctuation">..</span>.
  <span class="token keyword">done</span>

  <span class="token comment"># &#x5199;&#x6210;&#x4E00;&#x884C;&#xFF0C;&#x9002;&#x5408;&#x4E0E;terminal&#x7EC8;&#x7AEF;&#x4F7F;&#x7528;,&#x6CE8;&#x610F;&#x4F7F;&#x7528;&#x5206;&#x53F7;&#x5206;&#x5F00;</span>
  <span class="token keyword">for</span> <span class="token for-or-select variable">var</span> <span class="token keyword">in</span> item1 item2 <span class="token punctuation">..</span>. <span class="token punctuation">;</span> <span class="token keyword">do</span> command1<span class="token punctuation">;</span> command2<span class="token punctuation">;</span><span class="token punctuation">..</span>.<span class="token punctuation">;</span><span class="token keyword">done</span><span class="token punctuation">;</span>
</code></pre>
</li>
<li><blockquote>
<p>for&#x5FAA;&#x73AF;&#x7684;&#x7279;&#x6B8A;&#x7528;&#x6CD5;&#xFF1A;</p>
<pre class="language-"><code class="lang-bash"><span class="token keyword">for</span> <span class="token variable"><span class="token punctuation">((</span>&#x53D8;&#x91CF;&#x521D;&#x59CB;&#x5316;<span class="token punctuation">;</span>&#x6761;&#x4EF6;&#x5224;&#x65AD;&#x8BED;&#x53E5;<span class="token punctuation">;</span>&#x63A7;&#x5236;&#x53D8;&#x91CF;&#x7684;&#x8BED;&#x53E5;<span class="token punctuation">))</span></span><span class="token punctuation">;</span> <span class="token keyword">do</span>
<span class="token comment"># &#x5FAA;&#x73AF;&#x8BED;&#x53E5;</span>
<span class="token keyword">done</span>
</code></pre>
</blockquote>
</li>
</ul>
</li>
<li><p>while&#x8BED;&#x53E5;</p>
<ul>
<li><pre class="language-"><code class="lang-shell">  <span class="token assign-left variable">int</span><span class="token operator">=</span><span class="token number">1</span>
  <span class="token keyword">while</span><span class="token variable"><span class="token punctuation">((</span> $int<span class="token operator">&lt;=</span><span class="token number">5</span> <span class="token punctuation">))</span></span>
  <span class="token keyword">do</span>
      <span class="token builtin class-name">echo</span> <span class="token variable">$int</span>
      <span class="token builtin class-name">let</span> <span class="token string">&quot;int++&quot;</span>
  <span class="token keyword">done</span>
  <span class="token comment"># &#x5199;&#x6210;&#x4E00;&#x884C;</span>
  <span class="token keyword">while</span> condition<span class="token punctuation">;</span><span class="token keyword">do</span> command1<span class="token punctuation">;</span><span class="token keyword">done</span><span class="token punctuation">;</span>

  <span class="token comment"># &#x8FD8;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x8BFB;&#x53D6;&#x952E;&#x76D8;&#x4FE1;&#x606F;</span>
  <span class="token builtin class-name">echo</span> <span class="token string">&quot;&#x6309;&#x4E0B;^+c&#x9000;&#x51FA;&quot;</span>
  <span class="token keyword">while</span> <span class="token builtin class-name">read</span> INPUT<span class="token punctuation">;</span><span class="token keyword">do</span> <span class="token builtin class-name">command</span><span class="token punctuation">;</span><span class="token keyword">done</span><span class="token punctuation">;</span>

  <span class="token comment"># &#x65E0;&#x9650;&#x5FAA;&#x73AF;&#x7684;&#x5199;&#x6CD5;</span>
  <span class="token keyword">while</span> <span class="token builtin class-name">:</span>
  <span class="token keyword">do</span>
      <span class="token builtin class-name">command</span>
  <span class="token keyword">done</span>
  <span class="token comment"># &#x6216;&#x8005;for (( ; ; ))</span>
</code></pre>
</li>
<li><blockquote>
<p>while&#x8BED;&#x53E5;&#x7684;&#x7279;&#x6B8A;&#x7528;&#x6CD5;&#xFF1A;</p>
<p><strong>&#x9010;&#x884C;&#x8BFB;&#x53D6;&#x6587;&#x4EF6;&#x4FE1;&#x606F;</strong></p>
<pre class="language-"><code class="lang-bash"><span class="token keyword">while</span> <span class="token builtin class-name">read</span> VARIABLE<span class="token punctuation">;</span><span class="token keyword">do</span>
<span class="token comment"># &#x5FAA;&#x73AF;&#x4F53;</span>
<span class="token keyword">done</span> <span class="token operator">&lt;&lt;</span> /<span class="token environment constant">PATH</span>/TO/FILE
</code></pre>
</blockquote>
</li>
</ul>
</li>
<li><p>until&#x8BED;&#x53E5;</p>
<ul>
<li><pre class="language-"><code class="lang-shell">  <span class="token comment"># &#x76F4;&#x5230;until&#x6EE1;&#x8DB3;&#x6761;&#x4EF6;</span>
  <span class="token assign-left variable">a</span><span class="token operator">=</span><span class="token number">0</span>
  <span class="token keyword">until</span> <span class="token punctuation">[</span> <span class="token operator">!</span> <span class="token variable">$a</span> -lt <span class="token number">10</span> <span class="token punctuation">]</span>
  <span class="token keyword">do</span>
     <span class="token builtin class-name">echo</span> <span class="token variable">$a</span>
     <span class="token assign-left variable">a</span><span class="token operator">=</span><span class="token variable"><span class="token variable">`</span><span class="token function">expr</span> $a + <span class="token number">1</span><span class="token variable">`</span></span>
  <span class="token keyword">done</span>
</code></pre>
</li>
</ul>
</li>
<li><p>case&#x8BED;&#x53E5;</p>
<ul>
<li><pre class="language-"><code class="lang-shell">  <span class="token keyword">case</span> value <span class="token keyword">in</span>
  value1<span class="token operator">|</span>value2<span class="token operator">|</span>value3<span class="token punctuation">..</span>.<span class="token punctuation">)</span>
      command1
      command2 <span class="token punctuation">..</span>.
      <span class="token punctuation">;</span><span class="token punctuation">;</span>
  *<span class="token punctuation">)</span>  <span class="token comment"># &#x5176;&#x4ED6;&#x503C;&#x6267;&#x884C;&#x8BE5;&#x5206;&#x652F;</span>
      <span class="token builtin class-name">command</span> <span class="token punctuation">..</span>.
      <span class="token punctuation">;</span><span class="token punctuation">;</span>
  <span class="token keyword">esac</span>
  <span class="token comment"># &#x53EF;&#x4EE5;&#x914D;&#x5408;continue&#x548C;break&#x4F7F;&#x7528;</span>
  <span class="token comment"># case&#x652F;&#x6301;glob&#x98CE;&#x683C;&#x7684;&#x901A;&#x914D;&#x7B26;</span>
  <span class="token comment"># &#xFF1F;&#x4EFB;&#x610F;&#x5355;&#x4E2A;&#x5B57;&#x7B26;    []&#x8303;&#x56F4;&#x5185;&#x4EFB;&#x610F;&#x5B57;&#x7B26;    a|b a&#x6216;&#x8005;b</span>
</code></pre>
</li>
</ul>
<h1 id="shell&#x51FD;&#x6570;"><a name="shell&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#shell&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>23. shell&#x51FD;&#x6570;</h1>
</li>
<li><p>shell &#x51FD;&#x6570;&#x7684;&#x4E24;&#x79CD;&#x5B9A;&#x4E49;&#x65B9;&#x5F0F;</p>
</li>
<li><pre class="language-"><code class="lang-shell"><span class="token number">1</span>. function_name <span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token number">2</span>. <span class="token keyword">function</span> function_name<span class="token punctuation">(</span><span class="token punctuation">)</span>
</code></pre>
</li>
<li><p>shell &#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x503C;</p>
</li>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># &#x4F7F;&#x7528;return&#x8FD4;&#x56DE;&#xFF0C;&#x8FD4;&#x56DE;0-255&#x7684;&#x6574;&#x6570;</span>
<span class="token builtin class-name">return</span> <span class="token punctuation">[</span><span class="token number">0</span>-255<span class="token punctuation">]</span>  <span class="token number">0</span>&#x4EE3;&#x8868;&#x6210;&#x529F;&#xFF0C;&#x5176;&#x4ED6;&#x503C;&#x4EE3;&#x8868;&#x5931;&#x8D25;
&#x6216;&#x8005;&#x4F7F;&#x7528;echo&#x6765;&#x4F5C;&#x4E3A;&#x8FD4;&#x56DE;&#x503C;
</code></pre>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># &#x51FD;&#x6570;&#x7684;&#x4F7F;&#x7528;&#x548C;&#x8FD4;&#x56DE;&#x503C;</span>
<span class="token function-name function">functionDemo</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token builtin class-name">command</span>
    <span class="token builtin class-name">echo</span> <span class="token string">&quot;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570; <span class="token variable">$1</span>&quot;</span> <span class="token punctuation">..</span>.
    <span class="token builtin class-name">return</span> <span class="token punctuation">$(</span><span class="token punctuation">)</span><span class="token punctuation">..</span>.
<span class="token punctuation">}</span>
<span class="token comment">#&#x8C03;&#x7528;&#x51FD;&#x6570;</span>
functionDemo para1 para2 <span class="token punctuation">..</span>.
<span class="token comment"># &#x63A5;&#x6536;&#x8FD4;&#x56DE;&#x503C;</span>
<span class="token builtin class-name">echo</span> <span class="token string">&quot;<span class="token variable">$?</span>&quot;</span>
</code></pre>
</li>
</ul>
</li>
</ul>
<h1 id="&#x5E93;&#x6587;&#x4EF6;"><a name="&#x5E93;&#x6587;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x5E93;&#x6587;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>24. &#x5E93;&#x6587;&#x4EF6;</h1>
<ul>
<li><p>&#x5E93;&#x6587;&#x4EF6;&#x540D;&#x7684;&#x540E;&#x7F00;&#x662F;&#x4EFB;&#x610F;&#x7684;&#xFF0C;&#x4F46;&#x4E00;&#x822C;&#x4F7F;&#x7528;<code>.lib</code></p>
</li>
<li><p>&#x5E93;&#x6587;&#x4EF6;&#x901A;&#x5E38;&#x6CA1;&#x6709;&#x53EF;&#x6267;&#x884C;&#x6743;&#x9650;</p>
</li>
<li><p>&#x5E93;&#x6587;&#x4EF6;&#x65E0;&#x9700;&#x548C;&#x811A;&#x672C;&#x5728;&#x540C;&#x7EA7;&#x76EE;&#x5F55;&#xFF0C;&#x53EA;&#x9700;&#x5728;&#x811A;&#x672C;&#x4E2D;&#x5236;&#x5B9A;&#x5373;&#x53EF;</p>
</li>
<li><p>&#x5E93;&#x6587;&#x4EF6;&#x7684;&#x7B2C;&#x4E00;&#x884C;&#x901A;&#x5E38;&#x4F7F;&#x7528;<code>#!/bin/echo</code>&#xFF0C;&#x8F93;&#x51FA;&#x8B66;&#x793A;&#x5185;&#x5BB9;&#xFF0C;&#x907F;&#x514D;&#x7528;&#x6237;&#x6267;&#x884C;</p>
</li>
<li><p>&#x5E93;&#x6587;&#x4EF6;&#x7684;&#x5F15;&#x7528;</p>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token builtin class-name">.</span> /home/suofeiya/test/lib/base_function.lib
</code></pre>
</li>
</ul>
</li>
</ul>
<h1 id="&#x6587;&#x4EF6;&#x641C;&#x7D22;"><a name="&#x6587;&#x4EF6;&#x641C;&#x7D22;" class="anchor-navigation-ex-anchor" href="#&#x6587;&#x4EF6;&#x641C;&#x7D22;"><i class="fa fa-link" aria-hidden="true"></i></a>25. &#x6587;&#x4EF6;&#x641C;&#x7D22;</h1>
<ul>
<li><p>&#x5E38;&#x89C1;&#x56DB;&#x79CD;&#x6587;&#x4EF6;&#x641C;&#x7D22;&#x547D;&#x4EE4;&#x7684;&#x4F7F;&#x7528;&#x573A;&#x666F;</p>
</li>
<li><p><a href="../home/suofeiya/.config/Typora/typora-user-images/1559042701316.png" data-lightbox="364bc6f2-ed31-4da4-b05d-937a444c501b" data-title="1559042701316"><img src="../home/suofeiya/.config/Typora/typora-user-images/1559042701316.png" alt="1559042701316"></a></p>
</li>
<li><p>find</p>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># find&#x547D;&#x4EE4;&#x53C2;&#x6570;</span>
-print  &#x6253;&#x5370;&#x8F93;&#x51FA;&#xFF0C;&#x9ED8;&#x8BA4;&#x9009;&#x9879;
-exec  &#x5BF9;&#x641C;&#x7D22;&#x7ED3;&#x679C;&#x8FDB;&#x4E00;&#x6B65;&#x5904;&#x7406;
    &#x56FA;&#x5B9A;&#x683C;&#x5F0F;&#x4E3A; -exec <span class="token string">&apos;command&apos;</span> <span class="token punctuation">{</span><span class="token punctuation">}</span> <span class="token punctuation">\</span><span class="token punctuation">;</span>
&#x903B;&#x8F91;&#x8FD0;&#x7B97;&#x7B26;&#xFF0C;&#x4E0E;&#x6216;&#x975E;&#xFF0C;-a,-o,-not<span class="token operator">|</span><span class="token operator">!</span>
-perm  &#x6309;&#x7167;&#x6587;&#x4EF6;&#x6743;&#x9650;&#x8FDB;&#x884C;&#x641C;&#x7D22;
-prune  &#x6392;&#x9664;&#x6307;&#x5B9A;&#x76EE;&#x5F55;&#xFF0C;&#x901A;&#x5E38;&#x4E0E;-path&#x4E00;&#x540C;&#x4F7F;&#x7528;
    &#x4F8B;&#x5B50;&#xFF1A;find <span class="token builtin class-name">.</span> -path dir1/ -prune -o -path dir2/ -prune -o <span class="token punctuation">..</span>.
-type  &#x6309;&#x7167;&#x6587;&#x4EF6;&#x7C7B;&#x578B;&#x8FDB;&#x884C;&#x641C;&#x7D22;
    <span class="token function">find</span> /tmp <span class="token punctuation">\</span><span class="token punctuation">(</span> -type f -o -type d -o -type l <span class="token punctuation">\</span><span class="token punctuation">)</span>  <span class="token comment"># &#x6CE8;&#x610F;&#x8F6C;&#x4E49;&#x90E8;&#x5206;</span>
-mtime  &#x6309;&#x7167;&#x6587;&#x4EF6;&#x65F6;&#x95F4;&#x8FDB;&#x884C;&#x641C;&#x7D22;
    -mtime +7 &#x5BFB;&#x627E;&#x4E03;&#x5929;&#x4E4B;&#x524D;&#x7684;&#x6587;&#x4EF6;&#x5185;&#x5BB9;&#xFF0C;<span class="token variable"><span class="token variable">`</span>-<span class="token variable">`</span></span>&#x76F8;&#x53CD;
    &#x7C7B;&#x4F3C;&#x8FD8;&#x6709;-amin, -atime, -cmin, -ctime, -mmin
</code></pre>
</li>
</ul>
</li>
</ul>
<ul>
<li><p>locate(&#x4E0D;&#x540C;&#x4E8E;find&#xFF0C;locate&#x5728;&#x6570;&#x636E;&#x5E93;&#x6587;&#x4EF6;&#x4E2D;&#x67E5;&#x627E;&#xFF0C;&#x4E14;&#x5C5E;&#x4E8E;&#x90E8;&#x5206;&#x67E5;&#x627E;)</p>
<ul>
<li><pre class="language-"><code class="lang-shell">&#x5177;&#x4F53;&#x67E5;&#x770B;man page
</code></pre>
</li>
<li><p>&#x624B;&#x52A8;&#x66F4;&#x65B0;&#x547D;&#x4EE4;&#xFF0C;<code>updatedb</code></p>
<ul>
<li>&#x7528;&#x6237;&#x66F4;&#x65B0;&#x7684;&#x6587;&#x4EF6;&#x662F;<code>/var/lib/mlocate/mlocate.db</code></li>
<li>&#x6240;&#x4F7F;&#x7528;&#x7684;&#x914D;&#x7F6E;&#x6587;&#x4EF6;&#x662F;<code>/etc/updatedb.conf</code></li>
</ul>
</li>
</ul>
</li>
<li><p>whereis</p>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># whereis &#x53C2;&#x6570;&#x5217;&#x8868;</span>
-b  &#x8FD4;&#x56DE;&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;
-m  &#x8FD4;&#x56DE;&#x5E2E;&#x52A9;&#x6587;&#x4EF6;
-s  &#x8FD4;&#x56DE;source&#x6587;&#x4EF6;
</code></pre>
</li>
</ul>
</li>
<li><p>which</p>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># which &#x53EA;&#x67E5;&#x627E;&#x4E8C;&#x8FDB;&#x5236;&#x6587;&#x4EF6;</span>
</code></pre>
</li>
</ul>
</li>
</ul>
<h1 id="&#x5176;&#x4ED6;"><a name="&#x5176;&#x4ED6;" class="anchor-navigation-ex-anchor" href="#&#x5176;&#x4ED6;"><i class="fa fa-link" aria-hidden="true"></i></a>26. &#x5176;&#x4ED6;</h1>
<ul>
<li><code>dialog</code>&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x7A97;&#x53E3;&#x5316;&#x53D8;&#x6210;</li>
</ul>
<h1 id="&#x6587;&#x4EF6;&#x5904;&#x7406;&#x4E09;&#x5251;&#x5BA2;"><a name="&#x6587;&#x4EF6;&#x5904;&#x7406;&#x4E09;&#x5251;&#x5BA2;" class="anchor-navigation-ex-anchor" href="#&#x6587;&#x4EF6;&#x5904;&#x7406;&#x4E09;&#x5251;&#x5BA2;"><i class="fa fa-link" aria-hidden="true"></i></a>27. &#x6587;&#x4EF6;&#x5904;&#x7406;&#x4E09;&#x5251;&#x5BA2;</h1>
<ul>
<li><p>grep(&#x6587;&#x672C;&#x8FC7;&#x6EE4;&#x5668;,&#x6B64;&#x5916;&#x8FD8;&#x6709;egrep&#x548C;fgrep)</p>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># &#x8BED;&#x6CD5;&#x89C4;&#x5219;</span>
grep/egrep <span class="token punctuation">[</span>option<span class="token punctuation">]</span> <span class="token punctuation">[</span>pattern<span class="token punctuation">]</span> <span class="token punctuation">[</span>file1<span class="token punctuation">]</span> <span class="token punctuation">[</span>file2<span class="token punctuation">]</span> <span class="token punctuation">..</span>.
stdout <span class="token operator">|</span> gerp/egerp
</code></pre>
</li>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># grep &#x5E38;&#x7528;&#x53C2;&#x6570;&#x5217;&#x8868;</span>
-v  &#x5339;&#x914D;&#x975E;pattern&#x884C;&#x4FE1;&#x606F;
-i  &#x5FFD;&#x7565;&#x5927;&#x5C0F;&#x5199;
-n  &#x663E;&#x793A;&#x884C;&#x53F7;
-r  &#x9012;&#x5F52;&#x641C;&#x7D22;
-E  &#x652F;&#x6301;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x6269;&#x5C55;&#xFF0C;&#x7B49;&#x540C;&#x4E8E;egrep
-F  &#x4E0D;&#x6309;&#x7167;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x89C4;&#x5219;&#x5339;&#x914D;&#xFF0C;&#x5339;&#x914D;&#x539F;pattern&#x672C;&#x8EAB;&#x8868;&#x9762;&#x610F;&#x601D;
-c  &#x53EA;&#x5339;&#x914D;&#x884C;&#x7684;&#x603B;&#x6570;
-w  &#x5339;&#x914D;&#x6574;&#x4E2A;&#x5355;&#x8BCD;
-x  &#x5339;&#x914D;&#x6574;&#x884C;&#x4FE1;&#x606F;
-l  &#x53EA;&#x663E;&#x793A;&#x5339;&#x914D;&#x7684;&#x6587;&#x4EF6;&#x540D;&#xFF0C;&#x800C;&#x4E0D;&#x663E;&#x793A;&#x5185;&#x5BB9;
-s  &#x4E0D;&#x663E;&#x793A;&#x9519;&#x8BEF;&#x4FE1;&#x606F;
</code></pre>
</li>
<li><p>&#x4F8B;&#x5B50;&#xFF1A;</p>
<ul>
<li><pre class="language-"><code class="lang-bash"><span class="token function">grep</span> -v -E <span class="token string">&quot;(^#)|(^$)&quot;</span> <span class="token builtin class-name">test</span> <span class="token operator">&gt;</span> test2            <span class="token comment"># &#x53BB;&#x9664;&#x6587;&#x4EF6;&#x4E2D;&#x4EE5;#&#x5F00;&#x5934;&#x7684;&#x884C;&#x548C;&#x7A7A;&#x767D;&#x884C;&#xFF0C;&#x5E76;&#x8F93;&#x51FA;&#x4E3A;&#x65B0;&#x6587;&#x4EF6;</span>
</code></pre>
</li>
<li></li>
</ul>
</li>
</ul>
</li>
<li><p>sed( stream editor&#x6D41;&#x7F16;&#x8F91;&#x5668;)</p>
<ul>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># &#x8BED;&#x6CD5;&#x89C4;&#x5219;&#xFF0C;&#x6765;&#x81EA;man page</span>
<span class="token function">sed</span> <span class="token punctuation">[</span>OPTION<span class="token punctuation">]</span><span class="token punctuation">..</span>. <span class="token punctuation">{</span>script-only-if-no-other-script<span class="token punctuation">}</span> <span class="token punctuation">[</span>input-file<span class="token punctuation">]</span><span class="token punctuation">..</span>.
<span class="token comment"># &#x6CE8;&#x610F;&#x4F7F;&#x7528;&#x5355;&#x5F15;&#x53F7;</span>
</code></pre>
</li>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># sed &#x5E38;&#x7528;pattern&#x6A21;&#x5F0F;</span>
9command  &#x53EA;&#x5339;&#x914D;&#x7B2C;&#x4E5D;&#x884C;&#x5185;&#x5BB9;
<span class="token number">8</span>,9command  &#x5339;&#x914D;&#x7B2C;&#x516B;&#x884C;&#x5230;&#x7B2C;&#x4E5D;&#x884C;&#x7684;&#x5185;&#x5BB9;
<span class="token number">9</span>,+5command  &#x5339;&#x914D;&#x7B2C;&#x4E5D;&#x884C;&#x5230;&#x7B2C;&#x5341;&#x4E94;&#x884C;&#x4E4B;&#x95F4;&#x7684;&#x5185;&#x5BB9;
/pattern1/command  &#x5339;&#x914D;&#x5230;pattern1&#x7684;&#x5185;&#x5BB9;
/pattern1/,/pattern2/command
<span class="token number">9</span>,/pattern1/command
/pattern1/,9command
</code></pre>
</li>
<li><pre class="language-"><code class="lang-shell"><span class="token comment"># sed &#x7F16;&#x8F91;&#x547D;&#x4EE4;&#xFF0C;&#x4E0E;&#x5339;&#x914D;&#x6A21;&#x5F0F;&#x5DE7;&#x5999;&#x4F7F;&#x7528;</span>
p  &#x6253;&#x5370;&#xFF08;&#x6CE8;&#x610F;&#xFF1A;-n&#x9009;&#x9879;&#x548C;p&#x547D;&#x4EE4;&#x4E00;&#x8D77;&#x4F7F;&#x7528;&#x8868;&#x793A;&#x53EA;&#x6253;&#x5370;&#x90A3;&#x4E9B;&#x53D1;&#x751F;&#x66FF;&#x6362;&#x7684;&#x884C;&#xFF09;
a,i  &#x5206;&#x522B;&#x8868;&#x793A;&#x884C;&#x540E;&#xFF08;append&#xFF09;&#x884C;&#x524D;&#xFF08;insert&#xFF09;&#x8FFD;&#x52A0;&#xFF08;&#x6BCF;&#x4E00;&#x884C;&#x90FD;&#x8FDB;&#x884C;&#x6DFB;&#x52A0;&#xFF09;
r,w  &#x524D;&#x7F6E;&#x8868;&#x793A;&#x4ECE;&#x5916;&#x90E8;&#x6587;&#x4EF6;&#x8BFB;&#x5165;&#xFF0C;&#x5E76;&#x4E14;&#x5728;&#x5176;&#x884C;&#x540E;&#x8FFD;&#x52A0;&#xFF0C;&#x540E;&#x8005;&#x4EE3;&#x8868;&#x5C06;&#x5339;&#x914D;&#x7684;&#x884C;&#x5199;&#x5165;&#x5230;&#x5916;&#x90E8;&#x6587;&#x4EF6;&#x5F53;&#x4E2D;
d  &#x5220;&#x9664;
c &#x628A;&#x5339;&#x914D;&#x5230;&#x7684;&#x884C;&#x66FF;&#x6362;&#x4E3A;&#x6240;&#x8981;&#x66FF;&#x6362;&#x7684;&#x6587;&#x672C;
s/old/new/g  &#x4FEE;&#x6539;&#x6240;&#x6709;    s/old/new  &#x4FEE;&#x6539;&#x7B2C;&#x4E00;&#x4E2A;    s/old/new/2g  &#x4FEE;&#x6539;&#x7B2C;&#x4E8C;&#x4E2A;    s/old/new/ig    &#x4FEE;&#x6539;&#x6240;&#x6709;&#x5E76;&#x4E14;&#x5FFD;&#x7565;&#x5927;&#x5C0F;&#x5199;
</code></pre>
</li>
<li><pre class="language-"><code class="lang-shell"> <span class="token comment"># sed &#x9009;&#x9879;</span>
-n  &#x53EA;&#x6253;&#x5370;&#x6A21;&#x5F0F;&#x5339;&#x914D;&#x884C;*
-e  &#x76F4;&#x63A5;&#x5728;&#x547D;&#x4EE4;&#x884C;&#x4E2D;&#x8FDB;&#x884C;sed&#x7F16;&#x8F91;&#xFF0C;&#x9ED8;&#x8BA4;&#x9009;&#x9879;
    <span class="token function">sed</span> -n -e <span class="token string">&apos;/pattern1/p&apos;</span> -e <span class="token string">&apos;/pattern2/p&apos;</span> test.txt&#xFF08;&#x591A;&#x4E2A;&#x6761;&#x4EF6;&#xFF09;
-f  <span class="token operator">&lt;</span>script&#x6587;&#x4EF6;<span class="token operator">&gt;</span>&#x6216;--file<span class="token operator">=</span><span class="token operator">&lt;</span>script&#x6587;&#x4EF6;<span class="token operator">&gt;</span> &#x4EE5;&#x9009;&#x9879;&#x4E2D;&#x6307;&#x5B9A;&#x7684;script&#x6587;&#x4EF6;&#x6765;&#x5904;&#x7406;&#x8F93;&#x5165;&#x7684;&#x6587;&#x672C;&#x6587;&#x4EF6;
-r  &#x652F;&#x6301;&#x6269;&#x5C55;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;
-i  &#x76F4;&#x63A5;&#x4FEE;&#x6539;&#x6587;&#x4EF6;&#x5185;&#x5BB9;
</code></pre>
</li>
<li><p>&#x4F8B;&#x5B50;&#xFF1A;</p>
<ul>
<li><pre class="language-"><code class="lang-bash"> <span class="token function">sed</span> -n <span class="token string">&apos;/hello/a sed&apos;</span> <span class="token builtin class-name">test</span>            <span class="token comment"># &#x67E5;&#x627E;hello&#x5B57;&#x7B26;&#x4E32;&#x5E76;&#x5728;&#x5176;&#x540E;&#x9762;&#x4E00;&#x884C;&#x6DFB;&#x52A0;sed&#x5B57;&#x7B26;&#x4E32;</span>
 <span class="token function">sed</span> <span class="token string">&apos;5,8c changed&apos;</span> <span class="token builtin class-name">test</span>            
 <span class="token comment"># &#x4F7F;&#x7528;&#x6269;&#x5C55;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;</span>
 <span class="token function">sed</span> -n -r <span class="token string">&apos;s/(HELLO=)java/<span class="token entity" title="\1">\1</span>sed&apos;</span> <span class="token builtin class-name">test</span>            <span class="token comment"># &#x4F7F;&#x7528;&#x6B63;&#x5219;&#x5C06;&#x524D;&#x9762;HELLO=&#x5339;&#x914D;&#x5230;&#x540E;&#x9762;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x66FF;&#x6362;&#x4E3A;sed</span>
</code></pre>
</li>
<li></li>
</ul>
</li>
</ul>
</li>
<li><p>awk</p>
<ul>
<li><code>awk</code>&#x5176;&#x5B9E;&#x4E0D;&#x4EC5;&#x4EC5;&#x662F;&#x5DE5;&#x5177;&#x8F6F;&#x4EF6;&#xFF0C;&#x8FD8;&#x662F;&#x4E00;&#x79CD;&#x7F16;&#x7A0B;&#x8BED;&#x8A00;&#xFF0C;&#x6240;&#x4EE5;&#x5355;&#x72EC;&#x7B14;&#x8BB0;&#xFF0C;&#x89C1;<code>shell_awk.md</code></li>
</ul>
</li>
</ul>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; AGou 2020 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-03-02 20:42:24
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="iptables.html" class="navigation navigation-prev " aria-label="Previous page: iptables">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="shell_awk.html" class="navigation navigation-next " aria-label="Next page: shell_awk">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Linux Shell","level":"1.4.13","depth":2,"next":{"title":"shell_awk","level":"1.4.14","depth":2,"path":"Linux/shell_awk.md","ref":"Linux/shell_awk.md","articles":[]},"previous":{"title":"iptables","level":"1.4.12","depth":2,"path":"Linux/iptables.md","ref":"Linux/iptables.md","articles":[]},"dir":"ltr"},"config":{"plugins":["github@^2.0.0","edit-link@^2.0.2","anchors@^0.7.1","include-codeblock@^3.0.2","tbfed-pagefooter@^0.0.1","expandable-chapters-small@^0.1.7","anchor-navigation-ex@0.1.8","prism","-highlight","insert-logo","-lunr","-search","search-pro","splitter","lightbox","github-buttons","-sharing","sharing-plus","donate","code","-klipse","livereload"],"root":".","styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright © AGou 2020","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{"css":["prismjs/themes/prism-tomorrow.css"]},"github":{"url":"https://github.com/AGou-ops"},"livereload":{},"splitter":{},"search-pro":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"code":{"copyButtons":true},"donate":{"alipay":"https://agou-ops.github.io/images/alipay.png","alipayText":"支付宝打赏","button":"打赏","title":"","wechat":"https://agou-ops.github.io/images/wechatpay.png","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"anchor-navigation-ex":{"isRewritePageTitle":true,"tocLevel1Icon":"fa fa-hand-o-right","tocLevel2Icon":"fa fa-hand-o-right","tocLevel3Icon":"fa fa-hand-o-right"},"lightbox":{"jquery":true,"sameUuid":false},"github-buttons":{"repo":"AGou-ops/myStudyNote","types":["star","watch","fork"],"size":"small"},"expandable-chapters-small":{},"include-codeblock":{"check":false,"edit":true,"fixlang":false,"lang":"","template":"ace","theme":"chrome","unindent":true},"sharing":{"qq":true,"all":["douban","facebook","google","hatenaBookmark","instapaper","linkedin","twitter","weibo","messenger","qq","qzone","viber","vk","weibo","pocket","stumbleupon","whatsapp"],"douban":false,"facebook":false,"weibo":true,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":true,"linkedin":false},"edit-link":{"label":"Edit This Page","base":"https://github.com/AGou-ops/myStudyNote"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":true},"anchors":{},"insert-logo":{"style":"background: none; max-height: 50px; min-height: 50px","url":"https://s2.ax1x.com/2019/12/10/QBD0xO.jpg"}},"theme":"default","author":"AGou","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"AGou's StudyNote","language":"zh-hans","output.name":"site","links":{"sidebar":{"◆点击进入我的个人博客":"http://agou-ops.github.io"}},"gitbook":"3.2.3","description":"岂能尽如人意，但求无愧我心。"},"file":{"path":"Linux/Linux_shell.md","mtime":"2020-03-02T12:42:24.288Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-03-02T12:42:32.383Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-insert-logo/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lightbox/js/lightbox.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

